Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool searchArray(vector<int>& arr, int target) {
  4.         int l = 0, r = arr.size();
  5.         while(l < r - 1) {
  6.             int m = (l + r) / 2;
  7.             if (arr[m] > target) {
  8.                 r = m;
  9.             } else {
  10.                 l = m;
  11.             }
  12.         }
  13.         return arr[l] == target;
  14.     }
  15.     bool searchMatrix(vector<vector<int>>& matrix, int target) {
  16.         for (auto &arr: matrix) {
  17.             if (searchArray(arr, target))
  18.                 return true;
  19.         }
  20.         return false;
  21.     }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement