美文网首页
240 Search a 2D Matrix II

240 Search a 2D Matrix II

作者: larrymusk | 来源:发表于2017-12-05 11:20 被阅读0次
    bool searchMatrix(int** matrix, int matrixRowSize, int matrixColSize, int target) {
        if(matrixRowSize==0 || matrixColSize==0)
            return false;
    
        int x = matrixRowSize-1;
        int y = 0;
        while(1){
            if(matrix[x][y]==target)
                return true;
            else if(matrix[x][y] < target)
                y++;
            else 
                x--;
    
            if(x<0 || y > matrixColSize-1)
                return false;
        }
        
    }

    相关文章

      网友评论

          本文标题:240 Search a 2D Matrix II

          本文链接:https://www.haomeiwen.com/subject/rsiqixtx.html