Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool searchArray(vector<int>& arr, int target) {
- int l = 0, r = arr.size();
- while(l < r - 1) {
- int m = (l + r) / 2;
- if (arr[m] > target) {
- r = m;
- } else {
- l = m;
- }
- }
- return arr[l] == target;
- }
- bool searchMatrix(vector<vector<int>>& matrix, int target) {
- for (auto &arr: matrix) {
- if (searchArray(arr, target))
- return true;
- }
- return false;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement