当前位置:网站首页>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
边栏推荐
- C language course setting: cinema ticket selling management system
- EasyCVR更改录像存储路径,不生成录像文件如何解决?
- UI自動化測試從此告別手動下載瀏覽器驅動
- On the day 25K joined Tencent, I cried
- PlasticSCM 企业版Crack
- An elegant program for Euclid‘s algorithm
- 花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
- open graph协议
- Use object composition in preference to class inheritance
- Containerd series - what is containerd?
猜你喜欢
[untitled]
laravel8 导出Excle文件
北京程序员的真实一天!!!!!
The new project Galaxy token just announced by coinlist is gal
在线文本行固定长度填充工具
[software reverse - basic knowledge] analysis method, assembly instruction architecture
一文带你了解BI的前世今身与企业数字化转型的关系
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
How to use jedis of redis
Uni app change the default component style
随机推荐
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
A brief introduction to the behavior tree of unity AI
How is the entered query SQL statement executed?
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
IronXL for .NET 2022.6
provide/inject
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
DMX parameter exploration of grandma2 onpc 3.1.2.5
请问一下我的请求是条件更新,但在buffer中就被拦截了,这种情况我只能每次去flush缓存么?
As soon as I write the code, President Wang talks with me about the pattern all day
Containerd series - detailed explanation of plugins
技术教程:如何利用EasyDSS将直播流推到七牛云?
【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
Use threejs to create geometry and add materials, lights, shadows, animations, and axes
Thread Basics
Some enterprise interview questions of unity interview
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
BDF application - topology sequence
C # use awaiter