Skip to content

Commit f688941

Browse files
authored
Create 2149-rearrange-array-elements-by-sign.kt
1 parent 5b1a71f commit f688941

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Diff for: kotlin/2149-rearrange-array-elements-by-sign.kt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
fun rearrangeArray(nums: IntArray): IntArray {
3+
var pos = 0
4+
var neg = 1
5+
val res = IntArray (nums.size)
6+
7+
for (num in nums) {
8+
if (num > 0) {
9+
res[pos] = num
10+
pos += 2
11+
} else {
12+
res[neg] = num
13+
neg += 2
14+
}
15+
}
16+
17+
return res
18+
}
19+
20+
}

0 commit comments

Comments
 (0)