-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy path20.py
35 lines (31 loc) · 871 Bytes
/
20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
size = len(pushV)
popIndex = 0
a = []
for i in range(size):
if pushV[i] == popV[popIndex]:
popIndex += 1
else:
a.append(pushV[i])
if len(a)==0:
return True
if popIndex >= size:
return False
else:
size2 = len(a)
if size2 != size - popIndex:
return False
else:
flag = True
for i in range(size2):
if a[i] != popV[- (i+1)]:
flag = False
break
else:
popIndex += 1
return flag
s = Solution()
print s.IsPopOrder([1], [1])