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
No description provided.
The text was updated successfully, but these errors were encountered:
let searchRange = function(nums, target) { return [leftSearch(nums, target), rightSearch(nums, target)] } let leftSearch = function(nums, target) { let low = 0, high = nums.length - 1, mid while (low <= high) { mid = Math.floor((low+high)/2) if (nums[mid] < target) { low = mid + 1 } else if (nums[mid] > target) { high = mid - 1 } else if (nums[mid] === target) { // 这里不返回,继续收缩左侧边界 high = mid - 1 } } // 最后检查 low 是否越界或命中 if (low >= nums.length || nums[low] != target) return -1 return low } let rightSearch = function (nums, target) { let low = 0, high = nums.length - 1, mid while (low <= high) { mid = Math.floor((low+high)/2) if (nums[mid] < target) { low = mid + 1 } else if (nums[mid] > target) { high = mid - 1 } else if (nums[mid] === target) { // 这里不返回,继续收缩右侧边界 low = mid + 1 } } // 最后检查 high 是否越界或命中 if (high < 0 || nums[high] != target) return -1 return high }
复杂度分析:
附赠leetcode地址:leetcode
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: