FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/Week_01/id_140/Leetcode_905_140.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_140
/
Leetcode_905_140.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (44 loc) · 976 Bytes
Breadcrumbs
algorithm
/
Week_01
/
id_140
/
Leetcode_905_140.java
Copy path
File metadata and controls
47 lines (44 loc) · 976 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
/**
* 给定一个非负整数数组 A,返回一个由 A 的所有偶数元素组成的数组,后面跟 A 的所有奇数元素。
*
* 你可以返回满足此条件的任何数组作为答案。
*
*
*
* 示例:
*
* 输入:[3,1,2,4]
* 输出:[2,4,3,1]
* 输出 [4,2,3,1],[2,4,1,3] 和 [4,2,1,3] 也会被接受。
*
*
* 提示:
*
* 1 <= A.length <= 5000
* 0 <= A[i] <= 5000
*/
public
class
Leetcode_905_140
{
/**
* 程序入口
* @param A
* @return
*/
public
int
[]
sortArrayByParity
(
int
[]
A
) {
if
(
A
==
null
||
A
.
length
==
0
) {
return
new
int
[
0
];
}
int
even
=
0
;
int
odd
=
A
.
length
-
1
;
int
[]
ret
=
new
int
[
A
.
length
];
int
i
=
0
;
while
(
even
<=
odd
) {
if
(
A
[
i
] %
2
==
1
) {
ret
[
odd
--] =
A
[
i
];
}
else
{
ret
[
even
++] =
A
[
i
];
}
i
++;
}
return
ret
;
}
}
Back
|
FazBrowse Home
|
New Git URL