当前位置:网站首页>长度为n的入栈顺序的可能出栈顺序
长度为n的入栈顺序的可能出栈顺序
2022-07-05 04:00:00 【诗与浪子】
import itertools
def is_pop_order(push, pop):
""" 根据入栈顺序判断出栈顺序是否合理 :param push: 入栈顺序 :param pop: 出栈顺序 :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
边栏推荐
- error Couldn‘t find a package. JSON file in "your path“
- Clickhouse同步mysql(基于物化引擎)
- NEW:Devart dotConnect ADO. NET
- provide/inject
- Nmap使用手册学习记录
- DMX parameter exploration of grandma2 onpc 3.1.2.5
- Installation of postman and postman interceptor
- Differences among 10 addressing modes
- DFS and BFS concepts of trees and graphs
- 线程基础知识
猜你喜欢

【看完就懂系列】一文6000字教你从0到1实现接口自动化

程序员的视力怎么样? | 每日趣闻

灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?

error Couldn‘t find a package.json file in “你的路径“

Clickhouse synchronization MySQL (based on materialization engine)
![[positioning in JS]](/img/f1/02ce74fadc1f7524c7abca9db66c71.jpg)
[positioning in JS]

error Couldn‘t find a package. JSON file in "your path“

官宣!第三届云原生编程挑战赛正式启动!

陇原战“疫“2021网络安全大赛 Web EasyJaba

grandMA2 onPC 3.1.2.5的DMX参数摸索
随机推荐
Yuancosmic ecological panorama [2022 latest]
Quick start of UI component development of phantom engine [umg/slate]
lds链接的 顺序问题
[wp][introduction] brush weak type questions
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Assembly - getting started
【做题打卡】集成每日5题分享(第三期)
Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
Rust区块琏开发——签名加密与私钥公钥
[wp][入门]刷弱类型题目
我就一写代码的,王总整天和我谈格局...
Rome链分析
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
Analysis of glibc strlen implementation mode
线程基础知识
Wechat applet development process (with mind map)
MindFusion.Virtual Keyboard for WPF
The new project Galaxy token just announced by coinlist is gal
[charging station]_ Secular wisdom_ Philosophical wisdom _
What is test development? Why do so many companies hire test developers now?