题目描述
blablabla
样例
blablabla
算法1
() $O(n^2)$
blablabla
时间复杂度分析:blablabla
Python 代码
class Solution(object):
def isPopOrder(self, pushV, popV):
"""
:type pushV: list[int]
:type popV: list[int]
:rtype: bool
"""
if pushV == [] and popV == []:
return True
if len(pushV) != len(popV):
return False
sim = []
push_i= 0
pop_i = 0
while push_i < len(pushV):
sim.append(pushV[push_i])
while len(sim) != 0 and sim[-1] == popV[pop_i]:
sim.pop()
pop_i += 1
push_i += 1
if len(sim) == 0:
return True
return False