Given a rotated sorted array of distinct integers, return the peak element in the array. The peak element is the maximum element in the rotated sorted array. The array was originally sorted in ascending order and then rotated at some unknown pivot. The peak element is the point where the rotation occurs and is greater than its neighboring elements.
Example 1
Input: nums = [4,5,6,7,0,1,2]
Output: 7
Explanation: The maximum element is 7, which is greater than its neighbors and represents the peak of the rotated array.
Example 2
Input: nums = [3,4,5,1,2]
Output: 5
Explanation: The element 5 is the largest element and is the peak where the rotation happens.
Example 3
Input: nums = [1,2,3,4,5]
Output: 5
Explanation: The array is not rotated. The last element 5 is the maximum and therefore the peak element.
Sign in to write, run, and submit your solution against the full test suite.