var searchInsert = function (nums, target) {
let min = 0
let max = nums.length - 1
while (min <= max) {
const current = Math.floor((min + max) / 2)
if (nums[current] === target) return current
if (nums[current] < target) {
if (target <= nums[current + 1]) return current + 1
min = current + 1
} else {
max = current - 1
}
}
return min
}
var rangeSumBST = function (root, low, high) {
let result = 0
const sumTree = (head) => {
if (head === null) return
result += low <= head.val && head.val <= high ? head.val : 0
sumTree(head.left)
sumTree(head.right)
}
sumTree(root)
return result
}