Untitled
unknown
plain_text
a year ago
768 B
2
Indexable
Never
/* class Solution { public: bool searchMatrix(vector<vector<int>>& ma, int t) { int n=ma.size(), m=ma[0].size(); int r=0,c=n*m-1; while(r<c){ int mid =(c+r)/2; //if(ma[mid/m][mid%m]==t) return true; if(ma[mid/m][mid%m] < t) r=mid+1; else c=mid; } return (ma[c/m][c%m]==t); } }; */ class Solution {// binary tree search on public: bool searchMatrix(vector<vector<int>>& m, int t) { int R=m.size(),c=m[0].size()-1,r=0; //if(R==1) return m[0][0]==t; while(r<R && c>-1 ){ if(m[r][c]==t) return true; if(m[r][c] < t) r++; else c--; } return false; } };