当前位置:网站首页>长度为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
边栏推荐
- C语言课设:影院售票管理系统
- 线上故障突突突?如何紧急诊断、排查与恢复
- Differences among 10 addressing modes
- Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
- laravel8 导出Excle文件
- [C language] address book - dynamic and static implementation
- Analysis of dagger2 principle
- PlasticSCM 企业版Crack
- postman和postman interceptor的安装
- provide/inject
猜你喜欢

一文带你了解BI的前世今身与企业数字化转型的关系

【刷题】BFS题目精选

在线文本行固定长度填充工具

How to use jedis of redis

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

Installation of postman and postman interceptor

How about programmers' eyesight| Daily anecdotes

Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5

【web源码-代码审计方法】审计技巧及审计工具

测试开发是什么?为什么现在那么多公司都要招聘测试开发?
随机推荐
反絮凝剂-氨碘肽滴眼液
Wechat applet development process (with mind map)
【软件逆向-基础知识】分析方法、汇编指令体系结构
EasyCVR更改录像存储路径,不生成录像文件如何解决?
Online sql to excel (xls/xlsx) tool
CTF stegano practice stegano 9
DFS and BFS concepts of trees and graphs
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
An elegant program for Euclid‘s algorithm
UI automation test farewell to manual download of browser driver
KVM virtualization
Analysis of dagger2 principle
speed or tempo in classical music
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
[wp]bmzclub几道题的writeup
Assembly - getting started
【软件逆向-分析工具】反汇编和反编译工具
UI自动化测试从此告别手动下载浏览器驱动
About authentication services (front and back, login, registration and exit, permission management)
Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)