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)

 

posted @ 2019-01-21 10:23  小学弟-  阅读(228)  评论(0编辑  收藏  举报