leetcode-5404-用栈操作数组

题目描述:

 

 

 

 提交:O(N)

class Solution:
    def buildArray(self, target: List[int], n: int) -> List[str]:
        res = []
        a = "Push"
        b = "Pop"
        index = 1
        for i in target:
            while index != i:
                res.append(a)
                res.append(b)
                index += 1
            res.append(a)
            index += 1
        return res

 

posted @ 2020-05-10 22:07  oldby  阅读(81)  评论(0编辑  收藏  举报