https://oj.leetcode.com/problems/search-a-2d-matrix/

http://blog.csdn.net/linhuanmars/article/details/24216235


Please read these:

http://leetcode.com/2010/10/searching-2d-sorted-matrix.html

http://leetcode.com/2010/10/searching-2d-sorted-matrix-part-ii.html

http://leetcode.com/2010/10/searching-2d-sorted-matrix-part-iii.html


public class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        // Search from right corner
        int n = matrix.length; // how many rows. 
        int m = matrix[0].length; // how many columns
        
        if (m <= 0 || n <= 0)
            return false;
        
        int i = 0; // 0 -> n - 1
        int j = m - 1; // m -1 -> 0
        while (i < n && j >= 0)
        {
            int v = matrix[i][j];
            if (v == target)
                return true;
            else if (v > target)
                j --;
            else 
                i ++;
        }
        return false;
    }
}