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 searchInsert = 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 start }
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: