You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
559 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package class009;
public class Code02_SearchA2DMatrixII {
/*
* 评测代码可以直接去leetcode搜索Search a 2D Matrix II
*
*/
public static boolean searchMatrix(int[][] m, int target) {
if (m == null || m.length == 0 || m[0] == null || m[0].length == 0) {
return false;
}
int N = m.length;
int M = m[0].length;
int row = 0;
int col = M - 1;
while (row < N && col >= 0) {
if (m[row][col] > target) {
col--;
} else if (m[row][col] < target) {
row++;
} else {
return true;
}
}
return false;
}
}