class Solution: def buildArray(self, target, n: int): res = [] index = 0 # target's index curr = 1 # curr num while index < len(target): if target[index] == curr: res.append("Push") index += 1 else: res.append("Push") res.append("Pop") curr += 1 return res sol = Solution() print(sol.buildArray([1, 3], 3)) print(sol.buildArray([1, 2, 3], 3)) print(sol.buildArray([1, 2], 4)) |