Loading

剑指 Offer 04. 二维数组中的查找

https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof/

思路:
int[][]的时候,二维数组.length返回的是数组的行数
把这个转化成图,搜索二叉树

class Solution {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        int i = matrix.length - 1,j = 0;
        while(i >= 0 && j < matrix[0].length){
            if(matrix[i][j] > target) i--;
            else if(matrix[i][j] < target) j++;
            else return true;
        }
        return false;
    }
}
posted @ 2021-11-14 10:04  Zhbeii  阅读(17)  评论(0)    收藏  举报