We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1ad8ef4 commit 121ad5fCopy full SHA for 121ad5f
scripts/algorithms/R/Rearrange Array Elements by Sign/Rearrange Array Elements by Sign.java
@@ -1,25 +1,24 @@
1
+// Runtime: 13 ms (Top 29.67%) | Memory: 225.1 MB (Top 38.94%)
2
class Solution {
3
public int[] rearrangeArray(int[] nums) {
4
int[] res = new int[nums.length];
5
int resIdx = 0;
6
int posIdx = -1;
7
int minusIdx = -1;
8
-
9
for(int i=0;i<nums.length;i++){
10
if(i % 2 == 0){
11
posIdx++;
12
while(nums[posIdx] <0 )posIdx++;
13
- res[resIdx++] = nums[posIdx];
+ res[resIdx++] = nums[posIdx];
14
}
15
else{
16
minusIdx++;
17
while(nums[minusIdx] > 0 )minusIdx++;
18
- res[resIdx++] = nums[minusIdx];
+ res[resIdx++] = nums[minusIdx];
19
20
21
22
23
return res;
24
25
-}
+}
0 commit comments