Created
August 25, 2020 05:44
-
-
Save faizankshaikh/801cc70d8a9200dafb6b5b8307651168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def __init__(self): | |
self.sum_val = 0 | |
def _checker(self, root: TreeNode, direction: str): | |
if root: | |
self._checker(root.left, "left") | |
if not root.left and not root.right and direction == "left": | |
# print("Adding", root.val, "to", self.sum_val) | |
self.sum_val += root.val | |
self._checker(root.right, "right") | |
def sumOfLeftLeaves(self, root: TreeNode) -> int: | |
self._checker(root, "") | |
# print("result is", self.sum_val) | |
return self.sum_val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment