lc 153, 102提交cpp代码

This commit is contained in:
3119005212
2021-05-11 20:06:47 +08:00
parent 3cdbea167c
commit 4b8249e57f
2 changed files with 55 additions and 0 deletions

View File

@@ -60,6 +60,8 @@
**题目代码**
Java Code:
```java
class Solution {
public int findMin(int[] nums) {
@@ -85,3 +87,27 @@ class Solution {
}
```
C++ Code:
```cpp
class Solution {
public:
int findMin(vector <int> & nums) {
int left = 0;
int right = nums.size() - 1;
while (left < right) {
if (nums[left] < nums[right]) {
return nums[left];
}
int mid = left + ((right - left) >> 1);
if (nums[left] > nums[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return nums[left];
}
};
```