mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
14 lines
311 B
Go
14 lines
311 B
Go
package leetcode
|
|
|
|
func validateStackSequences(pushed []int, popped []int) bool {
|
|
stack, j, N := []int{}, 0, len(pushed)
|
|
for _, x := range pushed {
|
|
stack = append(stack, x)
|
|
for len(stack) != 0 && j < N && stack[len(stack)-1] == popped[j] {
|
|
stack = stack[0 : len(stack)-1]
|
|
j++
|
|
}
|
|
}
|
|
return j == N
|
|
}
|