FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_21/LeetCode_153_021.cpp at master · feixiangcode/algorithm · GitHub
feixiangcode
/
algorithm
Public
forked from
algorithm001/algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
Week_01
/
id_21
/
LeetCode_153_021.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (39 loc) · 791 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_21
/
LeetCode_153_021.cpp
Copy path
File metadata and controls
47 lines (39 loc) · 791 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class
Solution
{
public:
int
findMin
(vector<
int
>& nums) {
for
(
int
i =
1
; i < nums.
size
(); i ++) {
if
(nums[i] < nums[i-
1
])
return
nums[i];
}
return
nums[
0
];
}
};
/*
* 二分法查找
*/
class
Solution
{
public:
int
findMin
(vector<
int
>& nums) {
if
(nums.
size
() ==
1
) {
return
nums[
0
];
}
int
left =
0
, right = nums.
size
() -
1
;
if
(nums[right] > nums[
0
]) {
return
nums[
0
];
}
while
(right >= left) {
int
mid = left + (right - left) /
2
;
if
(nums[mid] > nums[mid +
1
]) {
return
nums[mid +
1
];
}
if
(nums[mid -
1
] > nums[mid]) {
return
nums[mid];
}
if
(nums[mid] > nums[
0
]) {
left = mid +
1
;
}
else
{
right = mid -
1
;
}
}
return
-
1
;
}
};
Back
|
FazBrowse Home
|
New Git URL