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

Commitf1b0c10

Browse files
Merge pull requestneetcode-gh#3306 from benmak11/2149-rearrange-array
Create 2149-rearrange-array-elements-by-signs.java
2 parents0028da6 +c2d6e66 commitf1b0c10

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+
publicclassSolution {
2+
publicint[]rearrangeArray(int[]nums) {
3+
inti =0,j =1;
4+
int[]res =newint[nums.length];
5+
for (intk =0;k <nums.length;k++) {
6+
if (nums[k] >0) {
7+
res[i] =nums[k];
8+
i +=2;
9+
}else {
10+
res[j] =nums[k];
11+
j +=2;
12+
}
13+
}
14+
returnres;
15+
}
16+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp