We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。
[0,1,2,4,5,6,7]
[4,5,6,7,0,1,2]
请找出其中最小的元素。
注意数组中可能存在重复的元素。
Input: [1,3,5] Output: 1
Input: [2,2,2,0,1] Output: 0
The text was updated successfully, but these errors were encountered:
/** * @param {number[]} nums * @return {number} */ var findMin = function(nums) { let left = 0; let right = nums.length - 1; while(left < right) { const mid = (left + right) >> 1; if (nums[mid] > nums[right]) { left = mid + 1; } else if (nums[mid] < nums[right]) { right = mid; } else { right -= 1; } } return nums[left]; };
function findMin(nums: number[]): number { let left = 0; let right = nums.length - 1; while(left < right) { const mid = (left + right) >> 1; if (nums[mid] > nums[right]) { left = mid + 1; } else if (nums[mid] < nums[right]) { right = mid; } else { right -= 1; } } return nums[left]; };
Sorry, something went wrong.
No branches or pull requests
154. Find Minimum in Rotated Sorted Array II
假设按照升序排序的数组在预先未知的某个点上进行了旋转。
( 例如,数组
[0,1,2,4,5,6,7]
可能变为[4,5,6,7,0,1,2]
)。请找出其中最小的元素。
注意数组中可能存在重复的元素。
Example 1
Example 2
The text was updated successfully, but these errors were encountered: