Python recursive solution 5 lines.


  • 0
    S
    def sumOfLeftLeaves(self, root, isLeft=False):
        if not root: 
          return 0
        if not root.left and not root.right:
          return root.val if isLeft else 0
        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.