Last active
February 20, 2020 07:31
-
-
Save Lugriz/a1aa61cee45aa40e83fa1a4cadf3cbd1 to your computer and use it in GitHub Desktop.
Range Sum of BST (Leetcode)
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
class Solution: | |
def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int: | |
_sum = 0 | |
if root: | |
if root.val >= L and root.val <= R: | |
_sum += root.val | |
if root.val <= R: | |
_sum += self.rangeSumBST(root.right, L, R) | |
if root.val >= L: | |
_sum += self.rangeSumBST(root.left, L, R) | |
return _sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment