Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cd6a850

Browse files
Add Solution.java for 0922.Sort Array By Parity II
1 parent 0eaafc5 commit cd6a850

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int[] sortArrayByParityII(int[] A) {
3+
int j = 1, length = A.length;
4+
for (int i = 0; i < length; i += 2) {
5+
if ((A[i] & 1) != 0) {
6+
while ((A[j] & 1) != 0) j += 2;
7+
8+
// Swap A[i] and A[j]
9+
int tmp = A[i];
10+
A[i] = A[j];
11+
A[j] = tmp;
12+
}
13+
}
14+
return A;
15+
}
16+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /