Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def helper(self, root, sum):
- from collections import defaultdict
- if not root: return None
- result = defaultdict(int)
- result[root.val] += 1
- left, right = self.helper(root.left, sum), self.helper(root.right, sum)
- if left:
- for key in left:
- result[key+root.val] += left[key]
- if right:
- for key in right:
- result[key+root.val] += right[key]
- self.count += result[sum]
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement