Skip to content

Instantly share code, notes, and snippets.

@farsialgorithm
Created December 4, 2018 03:52
Show Gist options
  • Select an option

  • Save farsialgorithm/3460a452b319b062d54ef32c539e8567 to your computer and use it in GitHub Desktop.

Select an option

Save farsialgorithm/3460a452b319b062d54ef32c539e8567 to your computer and use it in GitHub Desktop.
def rangeSumBST(root, L, R):
def rangeSumBST_helper(node, L, R):
if not node:
return 0
if R<node.val:
return rangeSumBST_helper(node.left, L, R)
if node.val<L:
return rangeSumBST_helper(node.right, L, R)
return node.val + rangeSumBST_helper(node.left, L, R) +\
rangeSumBST_helper(node.right, L, R)
return rangeSumBST_helper(root, L, R)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment