Accepted C# Solution


  • 0
    M
    public bool SearchMatrix(int[,] matrix, int target) {
            if (matrix == null) return false;
     
            var len = matrix.GetUpperBound(0);
            var row = 0;
            var col = matrix.GetUpperBound(1);
    
            while (row <= len && col >= 0)
            {
                if (matrix[row, col] > target) col--;
                else if (matrix[row, col] < target) row++;
                else return true;
            }
            return false;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.