当前位置:网站首页>Possible stack order of stack order with length n
Possible stack order of stack order with length n
2022-07-05 04:01:00 【Poetry and prodigal son】
import itertools
def is_pop_order(push, pop):
""" Judge whether the stack order is reasonable according to the stack order :param push: Stack order :param pop: Out of stack order :return: """
if len(push) == 0:
return False
stack = []
j = 0
for i in range(len(push)):
stack.append(push[i])
while j < len(pop) and stack and stack[-1] == pop[j]:
stack.pop()
j += 1
if len(stack) == 0:
return True
else:
return False
if __name__ == '__main__':
push = '123'
sequences = list(itertools.permutations(push, 3))
for sequence in sequences:
pop = ''.join(sequence)
if is_pop_order(push, pop):
print(pop)
# 1 2 3
# 1 3 2
# 2 1 3
# 2 3 1
# 3 1 2 x
# 3 2 1
边栏推荐
- An elegant program for Euclid‘s algorithm
- English essential vocabulary 3400
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
- A brief introduction to the behavior tree of unity AI
- Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
- The architect started to write a HelloWorld
- 技术教程:如何利用EasyDSS将直播流推到七牛云?
- [web source code code code audit method] audit skills and tools
- Clickhouse synchronization MySQL (based on materialization engine)
- 在线SQL转Excel(xls/xlsx)工具
猜你喜欢
![[software reverse - basic knowledge] analysis method, assembly instruction architecture](/img/97/8001db1c572495a115d32d9dd7360e.png)
[software reverse - basic knowledge] analysis method, assembly instruction architecture

Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery

Use Firefox browser to quickly pick up Web image materials

Three level linkage demo of uniapp uview u-picker components

Wechat applet development process (with mind map)

【无标题】

基于TCP的移动端IM即时通讯开发仍然需要心跳保活
![[positioning in JS]](/img/f1/02ce74fadc1f7524c7abca9db66c71.jpg)
[positioning in JS]

IronXL for .NET 2022.6

特殊版:SpreadJS v15.1 VS SpreadJS v15.0
随机推荐
Some enterprise interview questions of unity interview
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
An elegant program for Euclid‘s algorithm
The architect started to write a HelloWorld
grandMA2 onPC 3.1.2.5的DMX参数摸索
北京程序员的真实一天!!!!!
Containerd series - detailed explanation of plugins
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
[positioning in JS]
[punch in questions] integrated daily 5-question sharing (phase III)
Assembly - getting started
[software reverse analysis tool] disassembly and decompilation tool
Interview summary: This is a comprehensive & detailed Android interview guide
[brush questions] BFS topic selection
Rust blockchain development - signature encryption and private key public key
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
ClickPaaS低代码平台
Uni app common functions /api
Containerization Foundation