Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the push-in and pop-up sequence of the stack with the skill of golang brushing leetcode

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report