Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 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.         if (arr[l] == target)
  14.             return true;
  15.     }
  16.     bool searchMatrix(vector<vector<int>>& matrix, int target) {
  17.         for (auto &arr: matrix) {
  18.             if (searchArray(arr, target))
  19.                 return true;
  20.         }
  21.         return false;
  22.     }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement