递归代码:递归实现很简单 '二叉树结点类' class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None '列表创建二叉树' def listcreattree(root,llist,i):###用列表递归创建二叉树, #它其实创建过程也是从根开始a开始,创左子树b,再创b的左子树,如果b的左子树为空,返回none. #再接着创建b的右子树, if i<len(llist): if l
Given a binary tree, return the preorder traversal of its nodes' values. Example: Input: [1,null,2,3] 1 \ 2 / 3 Output: [1,2,3] Follow up: Recursive solution is trivial, could you do it iteratively? 给定一个二叉树,返回它的 前序 遍历. 示例: 输入: [1,null,2,3] 1 \ 2 / 3