From 4d20f5dee92c1c1ebc8b001294a51fcb77ebc1c9 Mon Sep 17 00:00:00 2001 From: linlihong <747682928@qq.com> Date: Mon, 9 Sep 2024 09:47:19 +0800 Subject: [PATCH] =?UTF-8?q?2024/9/9=20Hot100=20matrix=20=E6=9C=80=E5=90=8E?= =?UTF-8?q?=E4=B8=80=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cool/hot100/matrix/Num240.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/cool/hot100/matrix/Num240.java diff --git a/src/main/java/com/cool/hot100/matrix/Num240.java b/src/main/java/com/cool/hot100/matrix/Num240.java new file mode 100644 index 0000000..a871604 --- /dev/null +++ b/src/main/java/com/cool/hot100/matrix/Num240.java @@ -0,0 +1,33 @@ +package com.cool.hot100.matrix; + +/** + * Created with IntelliJ IDEA. + * + * @Author: Cool + * @Date: 2024/09/09/09:08 + * DayNumber 1 + * Hard 2 + * Level ? + */ +public class Num240 { + + public boolean searchMatrix(int[][] matrix, int target) { + if (matrix.length == 0) { + return false; + } + int colLen = matrix[0].length; + int len = matrix.length; + int col = colLen - 1; + int row = 0; + while (col >= 0 && row < len) { + if (matrix[row][col] == target) { + return true; + } else if (matrix[row][col] < target) { + row++; + } else { + col--; + } + } + return false; + } +}