바위타는 두루미

[leetcode]94. Binary Tree Inorder Traversal 본문

Study/Algorithm

[leetcode]94. Binary Tree Inorder Traversal

DoRoMii 2019. 8. 9. 10:48
728x90

94. Binary Tree Inorder Traversal

 

Given a binary tree, return the inorder traversal of its nodes' values.

Example:

Input: [1,null,2,3]

    1 

      \

        2

     /

 3

Output: [1,3,2]

 

class Solution(object):
    def inorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        if not root:
            return []
        else:
            return self.inorderTraversal(root.left) + [root.val] + self.inorderTraversal(root.right)
Comments