题解
栈的压入、弹出序列
http://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106
python 实现。自己的一点小思路,欢迎指正。主要利用了list中的元素互不相同的特性
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if not pushV and not popV:
return True
if not pushV or not popV:
return False
popV_copy=popV[:]
for i in pushV:
if i not in popV_copy:
return False
else:
popV_copy.remove(i)
start = popV[0]
start_index = pushV.index(start)
for i in range(start_index):
if popV.index(pushV[i])<popV.index(pushV[i+1]):
return False
return True
