Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * // This is the ArrayReader's API interface.
- * // You should not implement it, or speculate about its implementation
- * class ArrayReader {
- * public:
- * int get(int index);
- * };
- */
- class Solution {
- public:
- int search(const ArrayReader& reader, int target) {
- int left = 0, right = 10000;
- while(left<=right){
- int mid = (left+right)/2;
- int val = reader.get(mid);
- if(val == target)
- return mid;
- else if(val > target)
- right = mid-1;
- else
- left = mid+1;
- }
- return -1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement