704. 二分查找
题目:
思路:
【1】常规二分代码
代码展示:
//时间0 ms 击败 100% //内存43.1 MB 击败 68.49% class Solution { public int search(int[] nums, int target) { int l = 0 , r = nums.length; while (l < r){ int mid = (r-l)/2 + l; if (nums[mid] == target){ return mid; }else if (nums[mid] > target){ r = mid; }else { l = mid+1; } } return -1; } }