标签:
https://leetcode.com/problems/search-a-2d-matrix/
1 class Solution { 2 public: 3 bool searchMatrix(vector<vector<int>>& matrix, int target) { 4 int m=matrix.size(); 5 int n=matrix.at(0).size(); 6 int resM=0; 7 int resN=0; 8 for(int i=0;i<m;i++) 9 { 10 if(matrix.at(i).at(0)<=target) 11 resM=i; 12 else 13 break; 14 } 15 for(int j=0;j<n;j++) 16 { 17 if(matrix.at(resM).at(j)<=target) 18 resN=j; 19 else 20 break; 21 } 22 if(matrix.at(resM).at(resN)==target) 23 return true; 24 else 25 return false; 26 27 28 } 29 };
标签:
原文地址:http://www.cnblogs.com/aguai1992/p/4642755.html