当前位置:网站首页>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'))
边栏推荐
- Basic function learning 02
- EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
- What is test development? Why do so many companies hire test developers now?
- @The problem of cross database query invalidation caused by transactional annotation
- Plasticscm enterprise crack
- What is the reason why the webrtc protocol video cannot be played on the easycvr platform?
- 面试汇总:这是一份全面&详细的Android面试指南
- 根据入栈顺序判断出栈顺序是否合理
- UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程
- Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
猜你喜欢
随机推荐
技术教程:如何利用EasyDSS将直播流推到七牛云?
About the recent experience of writing questions
Analysis of glibc strlen implementation mode
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
长度为n的入栈顺序的可能出栈顺序种数
[数组]566. 重塑矩阵-简单
【web审计-源码泄露】获取源码方法,利用工具
EasyCVR更改录像存储路径,不生成录像文件如何解决?
DMX parameter exploration of grandma2 onpc 3.1.2.5
陇原战“疫“2021网络安全大赛 Web EasyJaba
Interview summary: This is a comprehensive & detailed Android interview guide
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?
Plasticscm enterprise crack
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
The architect started to write a HelloWorld
On the day 25K joined Tencent, I cried
[brush questions] BFS topic selection
Basic function learning 02
面试汇总:这是一份全面&详细的Android面试指南
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information