題庫
00:00

19. Search in Rotated Sorted Array

中等二分搜尋AmazonGoogleMicrosoft

The integer array nums was sorted in ascending order and then rotated. Find the index of target in O(log n) time, or return -1 if it is absent.

範例 1:

輸入: nums = [4,5,6,7,0,1,2], target = 0
輸出: 4

範例 2:

輸入: nums = [4,5,6,7,0,1,2], target = 3
輸出: -1

限制條件:

  • 1 <= nums.length <= 5000
  • All values in nums are unique.
核心程式碼模式
● 已自動儲存第 1 行,第 1 欄