当前位置:网站首页>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
边栏推荐
- 灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
- 北京程序员的真实一天!!!!!
- The new project Galaxy token just announced by coinlist is gal
- Rome链分析
- Uni app change the default component style
- MindFusion.Virtual Keyboard for WPF
- IronXL for . NET 2022.6
- How about programmers' eyesight| Daily anecdotes
- CTF stegano practice stegano 9
- It took two nights to get Wu Enda's machine learning course certificate from Stanford University
猜你喜欢
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
[array]566 Reshape the matrix - simple
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
如何实现实时音视频聊天功能
我国算力规模排名全球第二:计算正向智算跨越
@The problem of cross database query invalidation caused by transactional annotation
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
Containerd series - what is containerd?
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
Some enterprise interview questions of unity interview
随机推荐
[positioning in JS]
provide/inject
An elegant program for Euclid‘s algorithm
[untitled]
基于TCP的移动端IM即时通讯开发仍然需要心跳保活
[wp]bmzclub几道题的writeup
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
天干地支纪年法中为什么是60年一个轮回,而不是120年
UI自动化测试从此告别手动下载浏览器驱动
ClickPaaS低代码平台
【看完就懂系列】一文6000字教你从0到1实现接口自动化
CTF stegano practice stegano 9
@The problem of cross database query invalidation caused by transactional annotation
[web Audit - source code disclosure] obtain source code methods and use tools
C # use awaiter
Thread Basics
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 2)
陇原战“疫“2021网络安全大赛 Web EasyJaba
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
Timing manager based on C #