Skip to content

Commit 43cc87b

Browse files
add 2149
1 parent ca24a6b commit 43cc87b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class _2149 {
7+
public static class Solution1 {
8+
public int[] rearrangeArray(int[] nums) {
9+
int[] ans = new int[nums.length];
10+
List<Integer> pos = new ArrayList<>();
11+
List<Integer> neg = new ArrayList<>();
12+
for (int i = 0; i < nums.length; i++) {
13+
if (nums[i] > 0) {
14+
pos.add(nums[i]);
15+
} else {
16+
neg.add(nums[i]);
17+
}
18+
}
19+
for (int i = 0, j = 0; i < nums.length && j < pos.size(); i++, j++) {
20+
ans[i] = pos.get(j);
21+
i++;
22+
ans[i] = neg.get(j);
23+
}
24+
return ans;
25+
}
26+
}
27+
}

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