FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_121/LeetCode_905_121.java at master · isnotnull/algorithm · GitHub
isnotnull
/
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_121
/
LeetCode_905_121.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (35 loc) · 1.01 KB
Breadcrumbs
algorithm
/
Week_01
/
id_121
/
LeetCode_905_121.java
Copy path
File metadata and controls
37 lines (35 loc) · 1.01 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
32
33
34
35
36
37
class
Solution
{
public
int
[]
sortArrayByParity
(
int
[]
A
) {
if
(
A
==
null
||
A
.
length
<
1
||
A
.
length
>
5000
){
return
null
;
}
int
head
=
0
;
int
tail
=
A
.
length
-
1
;
while
(
head
>=
0
&&
tail
>=
0
&&
head
<
A
.
length
&&
tail
<
A
.
length
&&
head
<
tail
){
if
(!
isOdd
(
A
[
head
]) &&
isOdd
(
A
[
tail
])){
head
++;
tail
--;
}
else
if
(
isOdd
(
A
[
head
]) && !
isOdd
(
A
[
tail
])){
swap
(
A
,
head
,
tail
);
head
++;
tail
--;
}
else
if
(
isOdd
(
A
[
head
]) &&
isOdd
(
A
[
tail
])){
tail
--;
}
else
if
(!
isOdd
(
A
[
head
]) && !
isOdd
(
A
[
tail
])){
head
++;
}
}
return
A
;
}
public
void
swap
(
int
[]
arr
,
int
head
,
int
tail
){
int
tmp
=
arr
[
head
];
arr
[
head
] =
arr
[
tail
];
arr
[
tail
] =
tmp
;
}
public
boolean
isOdd
(
int
a
){
if
(
a
%
2
==
1
){
//是奇数
return
true
;
}
return
false
;
}
}
Back
|
FazBrowse Home
|
New Git URL