class Solution {
public:
    /*
    a.首先从数组左下角搜索.
b.如果当前数字大于target,那么查找往上移一位,如果当前数字小于target,那么查找往右移一位。
c.查找到target,返回true; 如果越界,返回false;
    */
    bool Find(int target, vector<vector<int> > array) {
        if(array.empty()==true || array[0].empty() == true)
        return false;

        int lineCount = array.size();
        int collumCount = array[0].size();

        int left = lineCount - 1;
        int down = 0;

        while(left >=0 && down < collumCount){
            if(array[left][down] == target)
            return true;
            else if(array[left][down] < target){
                //bigger
                down++;
            }else{
                left--;
            }

        }
        return false;
    }
};




参考主要思路:

  1. 由于行列递增,可以得出:a.在一列中的某个数字,其上的数字都比它小b.在一行中的某个数字,其右的数字都比它大
  2. 搜索流程:a.首先从数组左下角搜索.b.如果当前数字大于target,那么查找往上移一位,如果当前数字小于target,那么查找往右移一位。c.查找到target,返回true; 如果越界,返回false;