【LeetCode】剑指 Offer 04. 二维数组中的查找
![在这里插入图片描述](https://img-blog.csdnimg.cn/4ad8675b6cb14e88a0f2c8caceedfb0f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAMzEzWVBIVTM=,size_20,color_FFFFFF,t_70,g_se,x_16)
package offer;
public class Solution04 {
public static void main(String[] args) {
int[][] nums = {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
Solution04 solution = new Solution04();
System.out.println(solution.method(nums, 33));
}
private boolean method(int[][] nums, int target){
int i = nums.length - 1;
int j = 0;
while(i >= 0 && j <= nums[0].length - 1){
if(nums[i][j] > target) i--;
else if(nums[i][j] < target) j++;
else return true;
}
return false;
}
}