diff --git a/problems/0035.搜索插入位置.md b/problems/0035.搜索插入位置.md index 384e4ad8..1c5ad2c8 100644 --- a/problems/0035.搜索插入位置.md +++ b/problems/0035.搜索插入位置.md @@ -257,7 +257,25 @@ class Solution: Go: +JavaScript: +```js +var searchInsert = function (nums, target) { + let l = 0, r = nums.length - 1, ans = nums.length; + while (l <= r) { + const mid = l + Math.floor((r - l) >> 1); + + if (target > nums[mid]) { + l = mid + 1; + } else { + ans = mid; + r = mid - 1; + } + } + + return ans; +}; +``` -----------------------