Advertisement
Guest User

test1111

a guest
Feb 16th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def helper(self, root, sum):
  2.         from collections import defaultdict
  3.         if not root: return None
  4.    
  5.         result = defaultdict(int)
  6.         result[root.val] += 1
  7.        
  8.  
  9.         left, right = self.helper(root.left, sum), self.helper(root.right, sum)
  10.        
  11.         if left:
  12.             for key in left:
  13.                 result[key+root.val] += left[key]
  14.         if right:
  15.             for key in right:
  16.                 result[key+root.val] += right[key]
  17.        
  18.         self.count +=  result[sum]
  19.            
  20.         return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement