How to solve the stack overflow caused by the creation of segment tree by js?

use JavaScript to build a segment tree, and recursion is used in the construction process. This should make the call stack overflow. I wonder if there is any other way to solve this problem.

< H1 > Code < / H1 >
   


judge that there is something wrong with the condition, and do not stop recursion in time


there is a problem in the calculation of the middle value of the left and right boundary, which should be:

let mid = (l + (r - l) / 2) | 0;
Menu