We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f474f61 commit d7ecfadCopy full SHA for d7ecfad
kotlin/0735-asteroid-collision.kt
@@ -0,0 +1,24 @@
1
+class Solution {
2
+ fun asteroidCollision(ast: IntArray): IntArray {
3
+ val stack = LinkedList<Int>()
4
+
5
+ for (_a in ast) {
6
+ var a = _a
7
+ while (stack.isNotEmpty() && a < 0 && stack.peekLast() > 0) {
8
+ val diff = a + stack.peekLast()
9
+ if (diff < 0) {
10
+ stack.removeLast()
11
+ } else if (diff > 0) {
12
+ a = 0
13
+ } else {
14
15
16
+ }
17
18
19
+ if (a != 0) stack.addLast(a)
20
21
22
+ return stack.toIntArray()
23
24
+}
0 commit comments