Clearly Python solution


  • 0
    N
    # 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 sumOfLeftLeaves(self, root, isLeft=False):
            """
            :type root: TreeNode
            :rtype: int
            """
            #return self.sumLeft(root)
            if root is None:
                return 0
                
            if root.left is None and root.right is None and isLeft:
                return root.val
    
            return self.sumOfLeftLeaves(root.left, True) + self.sumOfLeftLeaves(root.right)
    

Log in to reply
 

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