LeetCode: Find Minimum in Rotated Sorted Array Posted on January 11, 2018July 26, 2020 by braindenny Find Minimum in Rotated Sorted Array Similar Problems: LeetCode: Find Minimum in Rotated Sorted Array II LeetCode: Search in Rotated Sorted Array CheatSheet: Leetcode For Code Interview CheatSheet: Common Code Problems & Follow-ups Tag: #binarysearch, #rotatelist 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). Find the minimum element. You may assume no duplicate exists in the array. Github: code.dennyzhang.com Credits To: leetcode.com Leave me comments, if you have better ways to solve. // https://code.dennyzhang.com/find-minimum-in-rotated-sorted-array // Basic Ideas: binary search // If nums[mid] > nums[right], the starting point is in the right half // Otherwise, it's in the left half // Complexity: Time O(log(n)), Space O(1) func findMin(nums []int) int { left, right := 0, len(nums)-1 // must exists for left<right { mid := (right-left)/2+left if nums[mid] > nums[right] { left = mid+1 } else { right = mid } } return nums[left] } Post Views: 5