您的位置:首页 > 其它

240. Search a 2D Matrix II

2016-04-24 18:02 447 查看
//O(m+n) 220ms
class Solution {
public:
bool searchMatrix(vector<vector<int>>& m, int t) {
int a=m.size(),b=m[0].size();
if(a*b==0||m[0][0]>t||m[a-1][b-1]<t) return false;
int x=0,y=b-1;
while(x<a&&y>=0)
{
if(m[x][y]==t) return true;
if(m[x][y]<t) x++;
else y--;
}

return false;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: