題庫
00:00

20. Find First and Last Position of Element in Sorted Array

中等二分搜尋AmazonMicrosoft

Given an integer array nums sorted in ascending order and a target, return the starting and ending position of target, or [-1, -1] if it is absent.

範例 1:

輸入: nums = [5,7,7,8,8,10], target = 8
輸出: [3,4]

範例 2:

輸入: nums = [5,7,7,8,8,10], target = 6
輸出: [-1,-1]

限制條件:

  • 0 <= nums.length <= 10^5
  • nums is sorted in ascending order.
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄