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 d244491 commit 5ee93a8Copy full SHA for 5ee93a8
contest/src/main/java/com/github/contest/array/ArrayProdVariant.kt
@@ -51,5 +51,25 @@ fun applyOperationsProdVariant(nums: IntArray): IntArray {
51
nums[it] = 0
52
}
53
54
+ return nums
55
+}
56
+
57
58
+fun applyOperationsProdVariantII(nums: IntArray): IntArray {
59
+ nums.indices.drop(1).forEach { i ->
60
+ if (nums[i - 1] == nums[i]) {
61
+ nums[i - 1] *= 2
62
+ nums[i] = 0
63
+ }
64
65
66
+ var insertPos = 0
67
+ nums.forEach { num ->
68
+ if (num != 0) {
69
+ nums[insertPos++] = num
70
71
72
+ nums.fill(0, insertPos)
73
74
return nums
75
0 commit comments