A very simple recursive python solution


  • 0
    S

    """

    class Solution(object):

    def helper(self, result, root):
        if not root:
            return
        result.append(root.val)
        self.helper(result, root.left)
        self.helper(result, root.right)    
    
    def preorderTraversal(self, root):
        result = []
        self.helper(result, root)
        return result
    

    """


Log in to reply
 

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