How to realize the push-in and pop-up sequence of the stack with the skill of golang brushing leetcode
Xiaobian to share with you how golang brush leetcode skills to achieve stack push, pop sequence, I hope you have something to gain after reading this article, let's discuss it together!
Enter two integer sequences. The first sequence indicates the push order of the stack. Please determine whether the second sequence is the pop order of the stack. Assume that all the numbers pushed into the stack are unequal. For example, sequence {1, 2, 3, 4, 5} is a stack pushing sequence of a stack, sequence {4, 5, 3, 2, 1} is a pop-up sequence corresponding to the stack pushing sequence, but {4, 3, 5, 1, 2} cannot be a pop-up sequence of the stack pushing sequence.
Example 1:
Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output: true
Explanation: We can do this in the following order:
push(1), push(2), push(3), push(4), pop() -> 4,
push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
Example 2:
Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
Output: false
Explanation: 1 cannot pop up before 2.
Tip:
0