Skip to content

Commit c2d6e66

Browse files
committed
Create 2149-rearrange-array-elements-by-signs.java
1 parent bf0a87e commit c2d6e66

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+
public class Solution {
2+
public int[] rearrangeArray(int[] nums) {
3+
int i = 0, j = 1;
4+
int[] res = new int[nums.length];
5+
for (int k = 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+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy