Skip to content

Commit aa66520

Browse files
committed
Update and rename findMinimumInRotatedSortedArray.cpp to find-minimum-in-rotated-sorted-array.cpp
1 parent 3778d71 commit aa66520

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Time: O(logn)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int findMin(vector<int>& nums) {
7+
int left = 0, right = nums.size() - 1;
8+
9+
// Find min left s.t. nums[left] < nums[left'].
10+
while (left < right && nums[left] >= nums[right]) {
11+
int mid = left + (right - left) / 2;
12+
if (nums[mid] < nums[left]) {
13+
right = mid;
14+
} else {
15+
left = mid + 1;
16+
}
17+
}
18+
19+
return nums[left];
20+
21+
}
22+
};

C++/findMinimumInRotatedSortedArray.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)