题解 | 验证栈序列
验证栈序列
https://www.nowcoder.com/practice/d3178fe362dd4810b577c77c9e128fc5
N = int(input())
for _ in range(N):
n = int(input())
in_list = list(map(int,input().split()))
res_list = list(map(int,input().split()))
stack = []
out = []
j = 0
for i in in_list:
stack.append(i)
while stack:
if stack[-1] == res_list[j]:
out.append(stack.pop())
j += 1
else:
break
if out == res_list:
print("Yes")
else:
print("No")