1
class Solution {
2
public int[] rearrangeArray(int[] nums) {
3
int[] res = new int[nums.length];
4
int resIdx = 0;
5
int posIdx = -1;
6
int minusIdx = -1;
7

8
for (int i = 0; i < nums.length; i++) {
9
if (i % 2 == 0) {
10
posIdx++;
11
while (nums[posIdx] < 0) posIdx++;
12
res[resIdx++] = nums[posIdx];
13
} else {
14
minusIdx++;
15
while (nums[minusIdx] > 0) minusIdx++;
16
res[resIdx++] = nums[minusIdx];
17
}
18
}
19

20
return res;
21
}
22
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0