题目如下:
解题思路:凑数题+3,搞不懂为什么本题的难度是Hard,而【leetcode】590. N-ary Tree Postorder Traversal是Medium。
代码如下:
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def postorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ if root == None: return [] res = [] stack = [root] while len(stack) > 0: node = stack.pop(0) res.insert(0,node.val) if node.left != None: stack.insert(0,node.left) if node.right != None: stack.insert(0,node.right) return res
原文地址:https://www.cnblogs.com/seyjs/p/9399279.html
时间: 2024-10-31 09:08:42