这道题看到了解法又让我感受到了编程之美。
教会了我虽然框架能让人很快写出代码,但是真正优秀的代码总是能够不被框架约束!
参考了向北的稻草 的博客
class Solution:
def sumOfLeftLeaves(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root is None:
return 0
sum=0
if root.left is not None and root.left.left is None and root.left.right is None:
sum+=root.left.val
return sum+self.sumOfLeftLeaves(root.left)+self.sumOfLeftLeaves(root.right)