leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0154.cpp (434B)


      1 class Solution {
      2   public:
      3     int findMin(const vector<int> &nums) const {
      4         int low = 0, high = nums.size() - 1;
      5 
      6         while (low < high) {
      7             const int mid = low + (high - low) / 2;
      8             if (nums[mid] > nums[high])
      9                 low = mid + 1;
     10             else if (nums[mid] < nums[high])
     11                 high = mid;
     12             else
     13                 high--;
     14         }
     15 
     16         return nums[low];
     17     }
     18 };