Leetcode590. N-ary Tree Postorder Traversal
阿新 • • 發佈:2018-12-16
590. N-ary Tree Postorder Traversal
自己沒寫出來 優秀程式碼:""" # Definition for a Node. class Node(object): def __init__(self, val, children): self.val = val self.children = children """ class Solution(object): def postorder(self, root):""" :type root: Node :rtype: List[int] """ res=[] if root==None: return res stack=[root] while stack: curr=stack.pop() res.append(curr.val) stack.extend(curr.children) return res[::-1]
反思:1.列表的常見操作不熟悉
2.怎麼用list來處理樹結構,不知道
strategy:
1.用anki記憶一些list的常見操作
2.知道迭代和遞迴的區別