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; + } +}