Skip to content

Instantly share code, notes, and snippets.

@Lugriz
Last active February 20, 2020 07:31
Show Gist options
  • Save Lugriz/a1aa61cee45aa40e83fa1a4cadf3cbd1 to your computer and use it in GitHub Desktop.
Save Lugriz/a1aa61cee45aa40e83fa1a4cadf3cbd1 to your computer and use it in GitHub Desktop.
Range Sum of BST (Leetcode)
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