240. Search a 2D Matrix II

来源:互联网 发布:python搜索引擎书籍 编辑:程序博客网 时间:2024/05/08 16:11
//O(m+n) 220msclass 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;    }};
0 0
原创粉丝点击