剑指offer 二维数组查找

题目描述
在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

class Solution {
public:
    bool Find(int target, vector<vector<int> > array) {
        bool isFound = false;
		for (int i = 0, j = array.size() -1 ;isFound == false && i < array[0].size()&& j >= 0; )
          {
            if(target == array[i][j])
            {
                isFound = true;
			}
            else if (target < array[i][j])
            {
  	             j--;
            }
            else if (target > array[i][j])
            {
                i++;
			}
        }
        if (isFound == true)
        {
            return true;
		}
        else
        {
           return false; 
        }
    }
   
};
原文地址:https://www.cnblogs.com/miki-52/p/7570553.html