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).
假設有一個排序過的漸增陣列在某個未知的軸心被旋轉。
(舉例:[0,1,2,4,5,6,7] 可能變成 [4,5,6,7,0,1,2])。
給你一個目標值去搜尋,如果存在於陣列中請回傳索引值,否則回傳-1。
你可以假設陣列中不會存在重複的值。
你的演算法的時間複雜度必須在O(log n)之內。
7
到 0
的減少,這邊將這個減少稱作【斷層】。LeetCode
C++