Python recursive solution


  • 0
    J
    class Solution(object):
        def sumOfLeftLeaves(self, root, is_left=False):
            """
            :type root: TreeNode
            :rtype: int
            """
            if root == None or root.left == None and root.right == None and not is_left:
                return 0
            if root.left == None and root.right == None and is_left:
                return root.val
     
            return self.sumOfLeftLeaves(root.left, True) + self.sumOfLeftLeaves(root.right, False)
    

Log in to reply
 

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