当前位置:网站首页>根据入栈顺序判断出栈顺序是否合理
根据入栈顺序判断出栈顺序是否合理
2022-07-05 04:00:00 【诗与浪子】
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
print(is_pop_order('1234', '4321'))
print(is_pop_order('1234', '1423'))
print(is_pop_order('1234', '2134'))
边栏推荐
- UI automation test farewell to manual download of browser driver
- C language course setting: cinema ticket selling management system
- [wp][introduction] brush weak type questions
- 线程基础知识
- 【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞
- 陇原战“疫“2021网络安全大赛 Web EasyJaba
- As soon as I write the code, President Wang talks with me about the pattern all day
- Pyqt5 displays file names and pictures
- 阿里云ECS使用cloudfs4oss挂载OSS
- [wp][入门]刷弱类型题目
猜你喜欢
Quick start of UI component development of phantom engine [umg/slate]
Interview summary: This is a comprehensive & detailed Android interview guide
@Transactional 注解导致跨库查询失效的问题
Containerd series - what is containerd?
Online sql to excel (xls/xlsx) tool
How about programmers' eyesight| Daily anecdotes
UI automation test farewell to manual download of browser driver
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
CTF stegano practice stegano 9
随机推荐
阿里云ECS使用cloudfs4oss挂载OSS
企业级:Spire.Office for .NET:Platinum|7.7.x
Analysis of glibc strlen implementation mode
[数组]566. 重塑矩阵-简单
About the recent experience of writing questions
postman和postman interceptor的安装
[untitled]
What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
Rome链分析
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
error Couldn‘t find a package. JSON file in "your path“
Basic function learning 02
Pyqt5 displays file names and pictures
DFS and BFS concepts of trees and graphs
@The problem of cross database query invalidation caused by transactional annotation
BDF application - topology sequence
Containerd series - what is containerd?
UI自動化測試從此告別手動下載瀏覽器驅動
Assembly - getting started
线程基础知识