Skip to content

Commit 9e84d05

Browse files
committed
Improved task 3467
1 parent 745ad35 commit 9e84d05

File tree

1 file changed

+10
-7
lines changed
  • src/main/kotlin/g3401_3500/s3467_transform_array_by_parity

1 file changed

+10
-7
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package g3401_3500.s3467_transform_array_by_parity
22

3-
// #Easy #2025_03_02_Time_11_ms_(100.00%)_Space_42.68_MB_(100.00%)
3+
// #Easy #2025_03_06_Time_1_ms_(100.00%)_Space_38.10_MB_(100.00%)
44

55
class Solution {
66
fun transformArray(nums: IntArray): IntArray {
7+
val size = nums.size
8+
val ans = IntArray(size)
9+
var countEven = 0
710
for (i in nums.indices) {
8-
if (nums[i] % 2 == 0) {
9-
nums[i] = 0
10-
} else {
11-
nums[i] = 1
11+
if (nums[i] and 1 == 0) {
12+
countEven++
1213
}
1314
}
14-
nums.sort()
15-
return nums
15+
for (i in countEven until size) {
16+
ans[i] = 1
17+
}
18+
return ans
1619
}
1720
}

0 commit comments

Comments
 (0)