题解 | #实现二叉树先序,中序和后序遍历#
实现二叉树先序,中序和后序遍历
http://www.nowcoder.com/practice/a9fec6c46a684ad5a3abd4e365a9d362
Binary Tree Traversal: recursion
class Solution: def threeOrders(self , root ): # write code here def preorder(root): if not root: return [] return [root.val]+preorder(root.left)+preorder(root.right) def inorder(root): if not root: return [] return inorder(root.left)+[root.val]+inorder(root.right) def postorder(root): if not root: return [] return postorder(root.left)+postorder(root.right)+[root.val] return [preorder(root),inorder(root),postorder(root)]