# 剑指offer-21.栈的压入、弹出序列-Python

## 记录

push和pop操作是混合使用的！！！
1,2,3,4,5
4,5,3,2,1

[1,2,3,4] 4=4 [1,2,3] [5,3,2,1]
[1,2,3,5] 5=5 [1,2,3] [3,2,1]
3=3 [1,2] [1,2]
2=2 [1] [1]
1=1 [] []

# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if not popV or not pushV:
return False
#辅助栈
stack = []
for i in pushV:
stack.append(i)
while stack and stack[-1] == popV[0]:
stack.pop()
popV.pop(0)
#stack结束
if not stack:
return True
else:
return False


1,2,3,4,5
4,3,5,1,2

# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if not popV or not pushV:
return False
i = 0
for j in range(len(pushV)):
while pushV[i] != popV[0]:
i += 1
if i>=len(pushV):
return False
pushV.pop(i)
popV.pop(0)
i -= 1
if not popV:
return True
else:
return False


05-15 84

06-25 347

07-05 507

04-10 127

03-04 57

05-25 676

03-13 19

02-23 55

05-16 572

08-08 122

07-17 68

04-25 577

01-14 23

03-08 581

04-04 92

03-10 60

10-24 21

08-07 134

08-21 79

04-14 58万+

03-13 14万+

03-01 13万+

03-04 13万+

03-08 4万+

03-08 7万+

04-25 6万+

03-10 13万+

03-12 11万+

03-13 11万+

03-14 1万+

03-18 9466

03-19 3万+

03-19 8万+

03-19 3万+

03-22 4万+

03-24 3万+

03-25 3万+

05-08 5万+

03-25 9万+

03-27 1万+

03-29 21万+

03-29 10万+

03-30 16万+

05-28 5815

05-28 1万+

04-02 4195

04-02 4万+

04-06 7万+

04-09 8万+

04-09 2万+

05-17 8153

04-11 3万+

04-15 6万+

04-18 4万+

04-20 4万+

04-24 3万+

04-29 6865

04-30 9821

04-30 9395

05-01 5751

05-03 1万+

05-16 5万+

05-06 1万+

05-08 4万+

05-10 3140

05-14 6206

05-14 1838

05-16 3438

05-16 1万+

05-20 858

05-18 8175

05-27 1137

05-18 3394

05-19 1万+

05-21 6834

05-21 6868

05-27 4880

05-25 4920

05-23 6401

05-28 1191

#### 因为无聊，我做出了一个能下载电影、动漫、电视剧的小程序，从此告别过去只能看部分视频简介的历史

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客