We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 745ad35 commit 9e84d05Copy full SHA for 9e84d05
src/main/kotlin/g3401_3500/s3467_transform_array_by_parity/Solution.kt
@@ -1,17 +1,20 @@
1
package g3401_3500.s3467_transform_array_by_parity
2
3
-// #Easy #2025_03_02_Time_11_ms_(100.00%)_Space_42.68_MB_(100.00%)
+// #Easy #2025_03_06_Time_1_ms_(100.00%)_Space_38.10_MB_(100.00%)
4
5
class Solution {
6
fun transformArray(nums: IntArray): IntArray {
7
+ val size = nums.size
8
+ val ans = IntArray(size)
9
+ var countEven = 0
10
for (i in nums.indices) {
- if (nums[i] % 2 == 0) {
- nums[i] = 0
- } else {
11
- nums[i] = 1
+ if (nums[i] and 1 == 0) {
12
+ countEven++
13
}
14
- nums.sort()
15
- return nums
+ for (i in countEven until size) {
16
+ ans[i] = 1
17
+ }
18
+ return ans
19
20
0 commit comments