4ms simple C++ code with explanation
In this problem, we have only three cases. \n\nCase 1. The leftmost value is less than the rightmost value in the list: This means that the list is not rotated.
In this problem, we have only three cases. \n\nCase 1. The leftmost value is less than the rightmost value in the list: This means that the list is not rotated. \ne.g>  [1 2 3 4 5 6 7 ]\n\nCase 2. The value in the middle of the list is greater than the leftmost and rightmost values in the list. \ne.g>  [ 4 5 6 7 0 1 2 3 ]\n\nCase 3. The value in the middle of the list is less than the leftmost and rightmost values in the list. \ne.g>  [ 5 6 7 0 1 2 3 4 ]\n\nAs you see in the examples above, if we have case 1, we just return the leftmost value in the list. If we have case 2, we just move to the right side of the list. If we have case 3 we need to move to the left side of the list. \n\nFollowing is the code that implements the concept described above.\n\n    int findMin(vector<int>& nums) {\n        int left = 0,  right = nums.size() - 1;\n        while(left < right) {\n            if(nums[left] < nums[right]) \n                return nums[left];\n                \n            int mid = (left + right)/2;\n            if(nums[mid] > nums[right])\n                left = mid + 1;\n            else\n                right = mid;\n        }\n        \n        return nums[left];\n    }
[]