题目:
题解:
class Solution:
def sumOfLeftLeaves(self, root: TreeNode) -> int:
if not root:
return 0
isLeafNode = lambda node: not node.left and not node.right
q = collections.deque([root])
ans = 0
while q:
node = q.popleft()
if node.left:
if isLeafNode(node.left):
ans += node.left.val
else:
q.append(node.left)
if node.right:
if not isLeafNode(node.right):
q.append(node.right)
return ans