bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 938. Range Sum of BST

938. Range Sum of BST

Leetcode Solutions

Depth First Search (DFS) Approach

  1. Start with the root node.
  2. If the current node is null, return 0.
  3. Initialize a variable sum to 0.
  4. If the current node's value is within the range [low, high], add it to sum.
  5. If the current node's value is greater than low, recursively call the function on the left child and add the result to sum.
  6. If the current node's value is less than high, recursively call the function on the right child and add the result to sum.
  7. Return the sum.
UML Thumbnail

Breadth First Search (BFS) Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...