Neat C++ solution


  • 0
    // OJ: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
    // Auther: github.com/lzl124631x
    // Time: O(logN)
    // Space: O(1)
    class Solution {
    public:
      int findMin(vector<int>& nums) {
        int L = 0, R = nums.size() - 1;
        while (L < R && nums[L] > nums[R]) {
          int M = (L + R) / 2;
          if (nums[M] > nums[R]) L = M + 1;
          else R = M;
        }
        return nums[L];
      }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.