LeetCode Find Minimum in Rotated Sorted Array

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.

 

 1 public class Solution {
 2     public int findMin(int[] num) {
 3         if (num.length==0) {
 4             return 0;
 5         }
 6         int minnum=num[0];
 7         for (int i : num) {
 8             if (i<minnum) {
 9                 minnum=i;
10                 break;
11             }
12         }
13         return minnum;
14     }
15 }

 

posted @ 2014-10-17 21:26  birdhack  阅读(85)  评论(0编辑  收藏  举报