題庫
00:00

6. Search Insert Position

簡單二分搜尋MicrosoftGoogle

Given a sorted array and a target value, return its index or the index where it would be inserted.

範例 1:

輸入: nums = [1,3,5,6], target = 5
輸出: 2

範例 2:

輸入: nums = [1,3,5,6], target = 2
輸出: 1

限制條件:

  • 1 <= nums.length <= 10^4
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄