Given an m x n matrix where each row is sorted left to right and each column is sorted top to bottom, search for a target value.
Start from top-right corner. If current > target: go left. If current < target: go down. If equal: return true.
- r=0, c=n-1.
- While r
=0: if matrix[r][c]==target return true; if > target c--; else r++. - Return false.
- Time Complexity: O(M+N)
- Space Complexity: O(1)