劍指offer——面試題8:旋轉數組的最小數字

本文轉載自:http://www.javaxxz.com/thread-359218-1-1.html

劍指offer——面試題8:旋轉數組的最小數字

哈哈哈,弱智題,一遍過

class Solution {
public:
   int minNumberInRotateArray(vector<int> rotateArray) {
       int n=rotateArray.size();
       if(n<=1) return n==0? 0:rotateArray[0];
       for(int i=1;i<n;i++){
           if(rotateArray[i]<rotateArray[i-1])
               return rotateArray[i];
       }
       return rotateArray[0];
   }
};


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章