标签:
这题很简单
class Solution { public: bool searchMatrix(vector<vector<int>>& matrix, int target) { int m=matrix.size(); int n=matrix[0].size(); int l=0,r=m-1,mid; if(target>matrix[m-1][n-1]||target<matrix[0][0]) return false; while(l<r) { mid=l+(r-l)/2; if(target==matrix[mid][n-1]) return true; else if(target<matrix[mid][n-1]) r=mid; else l=mid+1; } int index=r; l=0; r=n-1; while(l<=r) { mid=l+(r-l)/2; if(target==matrix[index][mid]) return true; else if(target<matrix[index][mid]) r=mid-1; else l=mid+1; } return false; } };
标签:
原文地址:http://www.cnblogs.com/qiaozhoulin/p/4580196.html