题目如下:
解题思路:凑数题+3,搞不懂为什么本题的难度是Hard,而是Medium。
代码如下:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass 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