這道題看到了解法又讓我感受到了編程之美。
教會了我雖然框架能讓人很快寫出代碼,但是真正優秀的代碼總是能夠不被框架約束!
參考了向北的稻草 的博客
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)