Files
LeetCode-Go/leetcode/0946.Validate-Stack-Sequences/946. Validate Stack Sequences.go
2020-08-07 17:06:53 +08:00

18 lines
422 B
Go

package leetcode
import "fmt"
func validateStackSequences(pushed []int, popped []int) bool {
stack, j, N := []int{}, 0, len(pushed)
for _, x := range pushed {
stack = append(stack, x)
fmt.Printf("stack = %v j = %v\n", stack, j)
for len(stack) != 0 && j < N && stack[len(stack)-1] == popped[j] {
stack = stack[0 : len(stack)-1]
j++
}
fmt.Printf("*****stack = %v j = %v\n", stack, j)
}
return j == N
}