当前位置:网站首页>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
边栏推荐
- [positioning in JS]
- 如何实现实时音视频聊天功能
- UI automation test farewell to manual download of browser driver
- Rome链分析
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
- NEW:Devart dotConnect ADO.NET
- 已解决(sqlalchemy+pandas.read_sql)AttributeError: ‘Engine‘ object has no attribute ‘execution_options‘
- 【无标题】
- Installation of postman and postman interceptor
猜你喜欢

如何实现实时音视频聊天功能

为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?

Containerd series - what is containerd?

Use of vscode software

The new project Galaxy token just announced by coinlist is gal

Use threejs to create geometry and add materials, lights, shadows, animations, and axes

NEW:Devart dotConnect ADO.NET

postman和postman interceptor的安装

输入的查询SQL语句,是如何执行的?

It took two nights to get Wu Enda's machine learning course certificate from Stanford University
随机推荐
Three level linkage demo of uniapp uview u-picker components
How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
Containerd series - what is containerd?
Laravel8 export excel file
Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
Plasticscm enterprise crack
【web审计-源码泄露】获取源码方法,利用工具
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
UI自动化测试从此告别手动下载浏览器驱动
grandMA2 onPC 3.1.2.5的DMX参数摸索
Assembly - getting started
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
[punch in questions] integrated daily 5-question sharing (phase III)
How is the entered query SQL statement executed?
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
阿里云ECS使用cloudfs4oss挂载OSS
线上故障突突突?如何紧急诊断、排查与恢复
NEW:Devart dotConnect ADO.NET
Online sql to excel (xls/xlsx) tool
The architect started to write a HelloWorld