力扣404. 左叶子之和

原题链接

 1 class Solution:
 2     ans = 0
 3     def sumOfLeftLeaves(self, root: TreeNode) -> int:
 4         def dfs(root,flag):
 5             if not root:return
 6             if not root.left and not root.right and flag:
 7                 self.ans += root.val
 8             dfs(root.left, True)
 9             dfs(root.right, False)
10         dfs(root,False)
11         return self.ans
12         
13             
原文地址:https://www.cnblogs.com/deepspace/p/14321232.html