MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / Solution

Class Solution

LeetCode_problems/range-sum-of-bst/Solution.py:12–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11#Solution : Inorder traversal and range(DFS)
12class Solution:
13 def rangeSumBST(self, root: TreeNode, L: int, R: int) -> int:
14 output=[]
15 self.inorder(root,output)
16 sum=L+R
17 for i in range(len(output)):
18 if output[i]>L and output[i]<R:
19 sum+=output[i]
20 return sum
21 def inorder(self,root,output):
22 if root == None:
23 return
24 else:
25 self.inorder(root.left,output)
26 output.append(root.val)
27 self.inorder(root.right,output)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected