题解 | 验证栈序列
验证栈序列
https://www.nowcoder.com/practice/d3178fe362dd4810b577c77c9e128fc5
import sys n = int(input().strip()) for _ in range(n): length = int(input().strip()) pushed_s = list(map(int,input().strip().split(" "))) popped_s = list(map(int,input().strip().split(" "))) stack = [] j = 0 for i in range(length): stack.append(pushed_s[i]) while stack and stack[-1] == popped_s[j]: stack.pop() j += 1 if len(stack) == 0: print("Yes") else: print("No")