Skip to main content
Go to Latest
File
export default function searchInsert(nums: number[], target: number): number { const n = nums.length; let left = 0, right = n - 1, ans = n; while (left <= right) { const mid = ((right - left) >> 1) + left; if (target <= nums[mid]) { ans = mid; right = mid - 1; } else { left = mid + 1; } } return ans;}