题目:
解答:
1 class Solution { 2 public: 3 bool findNumberIn2DArray(vector<vector<int>>& matrix, int target) 4 { 5 int i=matrix.size()-1; 6 int j=0; 7 // 从左下角开始 8 while(i >=0 && j<matrix[0].size()) 9 { 10 if(matrix[i][j] == target) 11 { 12 return true; 13 } 14 else if(matrix[i][j]>target) 15 { 16 i--; 17 } 18 else 19 { 20 j++; 21 } 22 } 23 24 return false; 25 } 26 };
原文:https://www.cnblogs.com/ocpc/p/12856392.html