Skip to content

Commit 77d4982

Browse files
authored
Create 0946-validate-stack-sequences.kt
1 parent 915e84e commit 77d4982

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
fun validateStackSequences(pushed: IntArray, popped: IntArray): Boolean {
3+
var i = 0
4+
var stack = LinkedList<Int>()
5+
6+
for (n in pushed) {
7+
stack.addLast(n)
8+
9+
while (i < popped.size && popped[i] == stack.peekLast()) {
10+
stack.removeLast()
11+
i++
12+
}
13+
}
14+
15+
return stack.isEmpty()
16+
}
17+
}

0 commit comments

Comments
 (0)