Friday, December 5, 2014

Find Minimum in Rotated Sorted Array

Problem

Suppose a sorted array 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.

Idea

用二分查找[left,right], 每次二分的那个点pivot,一定会把数组分成一个有序的和一个无序的,最小值永远都在无序的那个里

Solution


No comments:

Post a Comment