We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
原题链接
理解二分算法可以参考:二分查找详解
// 左闭右闭区间 const search = function(nums, target) { let start = 0 let end = nums.length - 1 while (start <= end) { const mid = start + ((end - start) >> 1) if (nums[mid] === target) return mid if (nums[mid] < target) { start = mid + 1 } else { end = mid - 1 } } return -1 }
// 左闭右开区间 const search = function(nums, target) { let start = 0 let end = nums.length while (start < end) { const mid = start + ((end - start) >> 1) if (nums[mid] === target) return mid if (nums[mid] < target) { start = mid + 1 } else { end = mid } } return -1 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接
二分查找
理解二分算法可以参考:二分查找详解
The text was updated successfully, but these errors were encountered: