二叉树的前序遍历(递归)
2018-03-20 本文已影响11人
只为此心无垠
def preorder(self, root):
if root == None:
return None
self.nums.append(root.val)
self.preorder(root.left)
self.preorder(root.right)
def preorderTraversal(self, root):
# write your code here
self.nums = []
self.preorder(root)
return self.nums