I can't pass the test case [1,2,3,4,5], my output is 6, but expected one is 4. I even don't know what the tree will be look like by giving me [1,2,3,4,5].
Pleas help me to find my mistake. Thank you!
class Solution(object): def sumOfLeftLeaves(self, root): """ :type root: TreeNode :rtype: int """ if not root: return 0 return self.leftLeaves(root.left, True) + self.leftLeaves(root.right, False) def leftLeaves(self, root, is_left): if not root: return 0 it_val = root.val if is_left else 0 return it_val + self.leftLeaves(root.left, True) + self.leftLeaves(root.right, False)
@path I got it! So I misunderstood the question, right? LEAVES are those in the bottom ones! Oh my! Thank you very much!