Created
December 4, 2018 03:58
-
-
Save farsialgorithm/33dfb06d90398eff8d8de43cf16dad97 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
| from collections import deque | |
| def rangeSumBST(root, L, R): | |
| s = 0 | |
| queue = deque([root]) | |
| while queue: | |
| c = queue.popleft() | |
| if c: | |
| if R<c.val: | |
| queue.append(c.left) | |
| elif c.val<L: | |
| queue.append(c.right) | |
| else: | |
| s += c.val | |
| queue.append(c.left) | |
| queue.append(c.right) | |
| return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment