leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0704.cpp (399B)


0 class Solution {
1 public:
2 int search(vector<int> &nums, int target) {
3 int low = 0, high = nums.size() - 1;
4 while (low <= high) {
5 int mid = low + (high - low) / 2;
6 if (nums[mid] == target) return mid;
7 if (nums[mid] < target)
8 low = mid + 1;
9 else
10 high = mid - 1;
11 }
12 return -1;
13 }
14 };