C++
1 class Solution { 2 public: 3 bool Find(vector<vector<int> > array,int target) { 4 int rows = array.size(); 5 int cols = array[0].size(); 6 int x = cols - 1; 7 int y = 0; 8 while ( x >= 0 && y < rows ) { 9 if (array[x][y] == target) return true; 10 if (array[x][y] < target) y++; 11 if (array[x][y] > target) x--; 12 } 13 return false; 14 } 15 };
时间: 2024-10-23 15:54:32