We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ca24a6b commit 43cc87bCopy full SHA for 43cc87b
src/main/java/com/fishercoder/solutions/_2149.java
@@ -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