q = int(input())
for i in range(q):
n = int(input())
push = list(map(int, input().strip().split()))
pop = list(map(int, input().strip().split()))
stack = []
for i in range(n):
stack.append(push[i])
while len(stack) > 0 and stack[-1] == pop[0]:
stack.pop()
del pop[0]
if len(stack) == 0:
print("Yes")
else:
print("No")
在我做这个题目的时候,我首先想到的是用一个函数去定义,但后来发现,当写完函数之后,如果用循环去对于每一组判断,这会调用大的内存且浪费时间,本题不需要用函数。不知函数递归会如何?


京公网安备 11010502036488号