Question.
I didn't come up with any essential difference between storing data in a matrix. The conditions given by the question determine that each row is spliced in sequence and the final result is an ordered array, therefore, binary can be used directly in the entire matrix, except that the specific data can be calculated with the/and % values each time.
Class Solution {public: bool bsearch (vector <int> & metrix, int target, int n, int start, int end) {if (start> end) return false; int mid = (start + end)/2; int I = mid/n, j = mid % n; if (metrix [I] [j] = target) return true; if (metrix [I] [j]> target) return bsearch (metrix, target, n, start, mid-1); else return bsearch (metrix, target, n, mid + 1, end);} bool searchMatrix (vector <int> & matrix, int target) {int m = matrix. size (), n = matrix [0]. size (); return bsearch (matrix, target, n, 0, m * N-1 );}};