Given the root of a binary tree, return the sum of all left leaves.A leaf is a node with no children. A left leaf is a leaf that is the left child of another node.
from leetcode_py import TreeNodeclass Solution: # Time: O(n) # Space: O(h) def sum_of_left_leaves(self, root: TreeNode[int] | None) -> int: if root is None: return 0 if root.left is not None and root.left.left is None and root.left.right is None: return root.left.val + self.sum_of_left_leaves(root.right) return self.sum_of_left_leaves(root.left) + self.sum_of_left_leaves(root.right)