94. 二叉树的中序遍历
94. 二叉树的中序遍历
方法一
# 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 inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ # temp_list = [] # if root == None: # return temp_list # if root.left != None: # temp_list += self.inorderTraversal(root.left) # if root.val != None: # temp_list.append(root.val) # if root.right != None: # temp_list += self.inorderTraversal(root.right) # return temp_list if root==None: return [] return self.inorderTraversal(root.left)+[root.val]+self.inorderTraversal(root.right)