C# Solution


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

Log in to reply
 

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