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 76ec0bc commit e037ba7Copy full SHA for e037ba7
contest/src/main/java/com/github/contest/array/AlternativeSolutionArray.kt
@@ -39,4 +39,34 @@ fun sortArrayByParityIIAlternativeSolution(nums: IntArray): IntArray {
39
}
40
41
return nums
42
+}
43
+
44
+/**
45
+ * 2460. Apply Operations to an Array
46
+ * Alternative Solution
47
+ */
48
49
+fun applyOperationsAlternativeSolution(nums: IntArray): IntArray {
50
+ for (i in 0 until nums.size - 1) {
51
+ if (nums[i] == nums[i + 1]) {
52
+ nums[i] *= 2
53
+ nums[i + 1] = 0
54
+ }
55
56
57
+ var insertPosition = 0
58
+ for (i in nums.indices) {
59
+ if (nums[i] != 0) {
60
+ nums[insertPosition] = nums[i]
61
+ insertPosition++
62
63
64
65
+ while (insertPosition < nums.size) {
66
+ nums[insertPosition] = 0
67
68
69
70
+ return nums
71
72
0 commit comments