当前位置:网站首页>Sword finger offer (21): push in and pop-up sequence of stack
Sword finger offer (21): push in and pop-up sequence of stack
2022-07-26 13:01:00 【Konstanch】
solution 1: Borrow an auxiliary stack , Traversing the stack order , First put the first one on the stack , Here is 1, It then determines whether the top element on the stack is the first element in the stack order , Here is 4, Obviously 1!=4, So we continue to stack , Until the stack is equal , Push an element , Moves the stack order one bit backward , Until it's not equal , So the loop isopressure order traversal completes , If the secondary stack is not already empty , Indicates that the pop-up sequence is not the pop-up order of the stack !
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if len(popV) == 0 or len(pushV) != len(popV):
return False
stackData = []
for i in pushV:
stackData.append(i)# Borrow auxiliary stack , Traversing the stack order !
while len(stackData) and stackData[-1] == popV[0]:
stackData.pop()
popV.pop(0)
if len(stackData):
return False
return True
边栏推荐
- V00 - do whatever you want when you are old
- Backtracking - 46. Full arrangement
- Knowledge points of C language documents
- Flutter dart generates a list of random numbers that are not repeated in n intervals
- Interviewer: how to deal with high concurrency?
- Panorama of volcanic engine cloud growth plan: 30 + plans come out together, and military development advantage areas
- 父组件访问子组件的方法或参数 (子组件暴漏出方法defineExpose)
- 手机上买股票,在哪里开户比较安全?
- Yolov7 training dangerous goods identification pytorch
- JDBC gets connections from the connection pool (Druid connection pool)
猜你喜欢

新功能 | 智能开放搜索上线定制词权重模型

0 basic programming resources (collect first ~ read slowly ~)

New function | intelligent open search online customized word weight model

Various extensions of hcip-9.ospf

(int argc, char** argv) command line parameters in visual stdio (VS)

食品安全 | 网购的自制食品就是健康食品?莫要陷入这些误区

Kubernetes APIServer 限流策略

Kuzaobao: summary of Web3 encryption industry news on July 25

Transformer dominates the world? Depth wise conv has something to say

【TypeScript】TypeScript常用类型(下篇)
随机推荐
Does Flink CDC only support SQL client to submit SQL scripts
LCD notes (7) LCD driver framework_ Configure clock
Redisson distributed lock usage example (I)
【TypeScript】TypeScript常用类型(下篇)
Emerging security providers to learn about in 2022
Vs code set the method of ctrl+s saving and automatic formatting
Display inline+calc realizes left, middle and right layout, and the middle is adaptive
Commonly used list Why does isempty() suddenly report null?
子组件触发父组件自定义事件(defineEmits):子组件传值给父组件
How to remove underline and color when there is focus in the shutter textfield
PXE原理与配置
LCD笔记(7)LCD驱动程序框架_配置时钟
Backtracking - question 51 Queen n -- a classic backtracking problem that must be overcome
Shutter background graying effect, how transparency, gray mask
The "2022 Huawei developer competition eastern China division opening ceremony" was successfully held in Fuzhou
全国职业院校技能大赛网络安全B模块wirshark数据包分析 wireshark0051.pcap
Code examples explain the difference between [reentrant lock] and [non reentrant lock]?
父组件访问子组件的方法或参数 (子组件暴漏出方法defineExpose)
SLAM 02.整体框架
LCD笔记(6)LCD驱动程序框架_配置引脚