其实用迭代解法应该更简单
class Solution(object):
def sumOfLeftLeaves(self, root):
"""
:type root: TreeNode
:rtype: int
"""
self.Sum=0
def rec(root):
if not root:
return 0
if root.left and not root.left.left and not root.left.right:
self.Sum+=root.left.val
rec(root.left)
rec(root.right)
return self.Sum
return rec(root)