-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path702.cpp
More file actions
20 lines (18 loc) · 742 Bytes
/
702.cpp
File metadata and controls
20 lines (18 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
__________________________________________________________________________________________________
// Forward declaration of ArrayReader class.
class ArrayReader;
class Solution {
public:
int search(const ArrayReader& reader, int target) {
int left = 0, right = INT_MAX;
while (left < right) {
int mid = left + (right - left) / 2, x = reader.get(mid);
if (x == target) return mid;
else if (x < target) left = mid + 1;
else right = mid;
}
return -1;
}
};
__________________________________________________________________________________________________
__________________________________________________________________________________________________