class Solution { public: int search(vector<int>& nums, int target) { int low = 0, high = nums.size(); while(low < high){ int mid = low + (high - low)/2; // mid = low + high>>1 nums[mid] < target ? low = mid + 1 : high = mid; } return low<nums.size()&&nums[low] == target ? low: -1; // 查找的值可能越界需要判断。 } };