4 lines Python Solution

  • 0
    # 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, isT=False):
            :type root: TreeNode
            :rtype: int
            if root and isT and not root.left and not root.right:
                return root.val
                return self.sumOfLeftLeaves(root.left, True) + self.sumOfLeftLeaves(root.right) if root else 0

Log in to reply

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