From 02381a3aa1f29bbd57c07f91499e6dece8a7af24 Mon Sep 17 00:00:00 2001 From: aouos Date: Tue, 25 May 2021 13:59:15 +0800 Subject: [PATCH] =?UTF-8?q?0035.=E6=90=9C=E7=B4=A2=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0035.搜索插入位置.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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; +}; +``` -----------------------