当前位置:网站首页>Judge whether the stack order is reasonable according to the stack order
Judge whether the stack order is reasonable according to the stack order
2022-07-05 04:01:00 【Poetry and prodigal son】
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
print(is_pop_order('1234', '4321'))
print(is_pop_order('1234', '1423'))
print(is_pop_order('1234', '2134'))
边栏推荐
- provide/inject
- [web Audit - source code disclosure] obtain source code methods and use tools
- error Couldn‘t find a package. JSON file in "your path“
- ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
- 我就一写代码的,王总整天和我谈格局...
- Online text line fixed length fill tool
- DFS and BFS concepts of trees and graphs
- As soon as I write the code, President Wang talks with me about the pattern all day
- [charging station]_ Secular wisdom_ Philosophical wisdom _
- Use threejs to create geometry and add materials, lights, shadows, animations, and axes
猜你喜欢
@The problem of cross database query invalidation caused by transactional annotation
[untitled]
Clickhouse物化视图
我国算力规模排名全球第二:计算正向智算跨越
【看完就懂系列】一文6000字教你从0到1实现接口自动化
The new project Galaxy token just announced by coinlist is gal
技术教程:如何利用EasyDSS将直播流推到七牛云?
laravel8 导出Excle文件
[array]566 Reshape the matrix - simple
在线文本行固定长度填充工具
随机推荐
NEW:Devart dotConnect ADO.NET
输入的查询SQL语句,是如何执行的?
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
Enterprise level: spire Office for . NET:Platinum|7.7. x
Use object composition in preference to class inheritance
C # use awaiter
An elegant program for Euclid‘s algorithm
Online sql to excel (xls/xlsx) tool
@Transactional 注解导致跨库查询失效的问题
open graph协议
在线文本行固定长度填充工具
根据入栈顺序判断出栈顺序是否合理
Official announcement! The third cloud native programming challenge is officially launched!
grandMA2 onPC 3.1.2.5的DMX参数摸索
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
Analysis of glibc strlen implementation mode
As soon as I write the code, President Wang talks with me about the pattern all day
The architect started to write a HelloWorld
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
IronXL for . NET 2022.6