【leetcode】240. 搜索二维矩阵 II

 

bool searchMatrix(int** matrix, int matrixSize, int* matrixColSize, int target){
    int row = matrixSize-1;
    int col = 0;    
    while (row >= 0 && col < *matrixColSize) {
        if (matrix[row][col] > target) {
            row--;
        } else if (matrix[row][col] < target) {
            col++;
        } else { // found it
            return true;
        }
    }    
    return false; 
}

 

posted @ 2021-01-06 15:57  温暖了寂寞  阅读(47)  评论(0编辑  收藏  举报