The sword refers to Offer_Programming questions_1

Topic description

In a two-dimensional array, each row is sorted in increasing order from left to right, and each column is sorted in increasing order from top to bottom. Please complete a function, input such a two-dimensional array and an integer, and determine whether the array contains the integer.
 
class Solution {
public:
    bool Find(int target, vector<vector<int> > array) {
        int row = array.size();
        int low = array[0].size();
        int i=row-1,j=0;
        while(i>=0 && j<low) {
            if(array[i][j] == target) {
                return true;
            } else if(array[i][j] > target) {
                i--;
            } else {
                j++;
            }
        }
        return false;
    }
};

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324628545&siteId=291194637