leetcode.jp 博客
本网站所有文字及图片内容均来自网络,每周定时更新,仅供个人学习与研究,请勿用于商业用途。谢谢合作。

33. Search in Rotated Sorted Array

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.

Your algorithm's runtime complexity must be in the order of O(log n).

Example 1:

Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4

Example 2:

Input: nums = [4,5,6,7,0,1,2], target = 3
Output: -1

Difficulty:

Medium

Lock:

Normal

Company:

Adobe Alibaba Amazon Apple Baidu Bloomberg ByteDance Cisco eBay Expedia Facebook Goldman Sachs Google JPMorgan LinkedIn Microsoft NetEase Nutanix Nvidia Oracle Samsung Snapchat Tencent Tesla TripAdvisor Twitch Uber Visa VMware Walmart Labs Yahoo Zillow Zulily

Solution(Chinese):

LEETCODE 33. Search in Rotated Sorted Array 解题思路分析