FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_129/LeetCode_81_129.java 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_129
/
LeetCode_81_129.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (31 loc) · 1.04 KB
Breadcrumbs
algorithm
/
Week_01
/
id_129
/
LeetCode_81_129.java
Copy path
File metadata and controls
31 lines (31 loc) · 1.04 KB
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
public
class
LeetCode_81_129
{
public
boolean
search
(
int
[]
nums
,
int
target
) {
if
(
nums
==
null
||
nums
.
length
==
0
)
return
false
;
int
low
=
0
,
mid
;
int
high
=
nums
.
length
-
1
;
while
(
low
<=
high
) {
if
(
nums
[
low
] <
nums
[
high
] && (
target
<
nums
[
low
] ||
target
>
nums
[
high
]))
return
false
;
mid
=
low
+ ((
high
-
low
) >>
1
);
if
(
nums
[
mid
] ==
target
) {
return
true
;
}
if
(
nums
[
low
] ==
nums
[
mid
] &&
nums
[
high
] ==
nums
[
mid
]) {
low
++;
high
--;
}
else
if
(
nums
[
low
] <=
nums
[
mid
]) {
if
(
nums
[
low
] <=
target
&&
target
<
nums
[
mid
]) {
high
=
mid
-
1
;
}
else
{
low
=
mid
+
1
;
}
}
else
{
if
(
nums
[
mid
] <
target
&&
target
<=
nums
[
high
]) {
low
=
mid
+
1
;
}
else
{
high
=
mid
-
1
;
}
}
}
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL