Movatterモバイル変換


[0]ホーム

URL:


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

Commit866f095

Browse files
authored
Update Sort Array By Parity.java
1 parentc0bc4ab commit866f095

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

‎Easy/Sort Array By Parity.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
classSolution {
2-
publicint[]sortArrayByParity(int[]A) {
3-
intevenIdx =0;
4-
intoddIdx =A.length -1;
5-
while (evenIdx <oddIdx) {
6-
if (A[evenIdx] %2 ==0) {
7-
evenIdx++;
8-
}
9-
else {
10-
inttemp =A[evenIdx];
11-
A[evenIdx] =A[oddIdx];
12-
A[oddIdx--] =temp;
13-
}
2+
publicint[]sortArrayByParity(int[]nums) {
3+
intstart =0;
4+
intend =0;
5+
intn =nums.length;
6+
while (end <n) {
7+
if (nums[end] %2 ==0) {
8+
inttemp =nums[start];
9+
nums[start++] =nums[end];
10+
nums[end] =temp;
11+
}
12+
end++;
13+
}
14+
returnnums;
1415
}
15-
returnA;
16-
}
1716
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp