FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_102/leetcode_153_102.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_102
/
leetcode_153_102.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (31 loc) · 811 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_102
/
leetcode_153_102.cpp
Copy path
File metadata and controls
37 lines (31 loc) · 811 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
/*
* 存两个临时变量,left和right, 如果left>right,则返回right;
* 如果只有一个元素,则返回它自己;
* 如果没有旋转过,则返回第一个元素
*/
class
Solution
{
public:
int
findMin
(vector<
int
>& nums) {
int
count = nums.
size
();
if
(count ==
1
) {
return
nums[
0
];
}
int
left = nums[
0
];
int
right = nums[
1
];
if
(left > right) {
return
right;
}
int
i;
for
(i =
2
; i < count; i++) {
left = right;
right = nums[i];
if
(left > right) {
return
right;
}
}
if
(i == count) {
return
nums[
0
];
}
return
-
1
;
}
};
Back
|
FazBrowse Home
|
New Git URL