Skip to content

Instantly share code, notes, and snippets.

@faizankshaikh
Created August 25, 2020 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faizankshaikh/801cc70d8a9200dafb6b5b8307651168 to your computer and use it in GitHub Desktop.
Save faizankshaikh/801cc70d8a9200dafb6b5b8307651168 to your computer and use it in GitHub Desktop.
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