Skip to content

Commit 5b901b5

Browse files
authored
add cpp solution
1 parent 15c0d42 commit 5b901b5

File tree

1 file changed

+20
-0
lines changed
  • solution/0153.Find Minimum in Rotated Sorted Array

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int findMin(vector<int>& nums) {
4+
if (nums[0] <= nums.back())
5+
return nums[0] ;
6+
7+
int l = 0, r = nums.size() - 1 ;
8+
9+
while (l+1 < r)
10+
{
11+
const int mid = l + ((r-l) >> 1) ;
12+
if (nums[l] <= nums[mid])
13+
l = mid ;
14+
else
15+
r = mid ;
16+
}
17+
18+
return nums.at(r) ;
19+
}
20+
};

0 commit comments

Comments
 (0)