Share my Python Solution


  • 1
    M
    class Solution(object):
    def preorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        result = []
        def traverse(root):
            if not root: return
    
            result.append(root.val)
            traverse(root.left)
            traverse(root.right)
    
        traverse(root)
        return result

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.