当前位置:网站首页>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
边栏推荐
- 深度学习——LSTM基础
- Clickhouse物化视图
- What is test development? Why do so many companies hire test developers now?
- [wp][introduction] brush weak type questions
- Plasticscm enterprise crack
- 阿里云ECS使用cloudfs4oss挂载OSS
- Timing manager based on C #
- Clickhouse同步mysql(基于物化引擎)
- 企业级:Spire.Office for .NET:Platinum|7.7.x
- Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
猜你喜欢
EasyCVR更改录像存储路径,不生成录像文件如何解决?
@The problem of cross database query invalidation caused by transactional annotation
Enterprise level: spire Office for . NET:Platinum|7.7. x
[web Audit - source code disclosure] obtain source code methods and use tools
error Couldn‘t find a package.json file in “你的路径“
IronXL for .NET 2022.6
Wechat applet development process (with mind map)
Differences among 10 addressing modes
How about programmers' eyesight| Daily anecdotes
Deep learning - LSTM Foundation
随机推荐
面试汇总:这是一份全面&详细的Android面试指南
线上故障突突突?如何紧急诊断、排查与恢复
[wp][入门]刷弱类型题目
C语言课设:影院售票管理系统
Excuse me, my request is a condition update, but it is blocked in the buffer. In this case, can I only flush the cache every time?
【web审计-源码泄露】获取源码方法,利用工具
An elegant program for Euclid‘s algorithm
[untitled]
反絮凝剂-氨碘肽滴眼液
Containerd series - detailed explanation of plugins
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
【刷题】BFS题目精选
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
Threejs realizes sky box, panoramic scene, ground grass
函数基础学习02
[brush questions] BFS topic selection
Thread Basics
Plasticscm enterprise crack
Wechat applet development process (with mind map)
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?