Created
January 8, 2020 17:52
-
-
Save dionyziz/98749a1fd4ed0247ea9c03a30e1901f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import operator | |
from functools import partial, reduce | |
def flatten(node): | |
if not node: | |
return [] | |
return flatten(node.left) + [node.val] + flatten(node.right) | |
def rangeSumBST(root, L, R): | |
return reduce(operator.add, | |
filter(partial(operator.ge, R), | |
filter(partial(operator.le, L), flatten(root)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment