当前位置:网站首页>Sword finger offer (21): push in and pop-up sequence of stack
Sword finger offer (21): push in and pop-up sequence of stack
2022-07-26 13:01:00 【Konstanch】
solution 1: Borrow an auxiliary stack , Traversing the stack order , First put the first one on the stack , Here is 1, It then determines whether the top element on the stack is the first element in the stack order , Here is 4, Obviously 1!=4, So we continue to stack , Until the stack is equal , Push an element , Moves the stack order one bit backward , Until it's not equal , So the loop isopressure order traversal completes , If the secondary stack is not already empty , Indicates that the pop-up sequence is not the pop-up order of the stack !
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if len(popV) == 0 or len(pushV) != len(popV):
return False
stackData = []
for i in pushV:
stackData.append(i)# Borrow auxiliary stack , Traversing the stack order !
while len(stackData) and stackData[-1] == popV[0]:
stackData.pop()
popV.pop(0)
if len(stackData):
return False
return True
边栏推荐
- [typescript] typescript common types (Part 1)
- LCD笔记(7)LCD驱动程序框架_配置时钟
- Flutter dart generates a list of random numbers that are not repeated in n intervals
- Kubernetes Flannel:HOST-GW模式
- How to view encrypted information in text form
- 历史上的今天:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone...
- Display inline+calc realizes left, middle and right layout, and the middle is adaptive
- After being fined "paid leave" for one month, Google fired him who "loves" AI
- 最好的工程师,就是这样被你“逼”走的!
- Huawei recruited "talented teenagers" twice this year; 5.4 million twitter account information was leaked, with a selling price of $30000; Google fired engineers who believed in AI consciousness | gee
猜你喜欢

被罚“带薪休假”一个月后,谷歌解雇了“爱”上 AI 的他

Food safety | what food can be heated in a microwave oven? You should know these potential safety hazards

Slam 02. overall framework

The best engineer was "forced" away by you like this!

V00 - do whatever you want when you are old

笔记。。。。

C regards type as generic type T and uses it as generic type of method

Kuzaobao: summary of Web3 encryption industry news on July 25

Elementary notes of binary tree

一款超好用的神器Apifox,甩 Swagger 几条街...(荣耀典藏版)
随机推荐
数据库组成存储过程和函数
Huawei recruited "talented teenagers" twice this year; 5.4 million twitter account information was leaked, with a selling price of $30000; Google fired engineers who believed in AI consciousness | gee
Huawei ultra fusion fusioncube solution notes
Understand test.py in gaitset
V00 - do whatever you want when you are old
[5gc] what is 5g slice? How does 5g slice work?
Backtracking - 491. Incremental subsequence
Detailed interpretation of hole convolution (input and output size analysis)
LCD notes (6) LCD driver framework_ Configuration pin
Today in history: IBM obtained the first patent; Verizon acquires Yahoo; Amazon releases fire phone
Kubernetes APIServer 限流策略
Today's sleep quality record 75 points
A super easy-to-use artifact apifox, throw swagger a few streets... (glory Collection Edition)
Kuzaobao: summary of Web3 encryption industry news on July 25
Kubernetes---- installing and deploying NFS servers
食品安全 | 微波炉什么食品都能加热?这些安全隐患要知道
VS code 设置Ctrl+S保存,自动格式化的方法
食品安全 | 随便果可以”随便“吃吗?
Router. Push(), router. Reply(), router. Go()
Transformer dominates the world? Depth wise conv has something to say