将给定的二叉搜索树中的所有较大值添加到每个节点中
在这里我们将看到一个有趣的问题,我们将为一个给定的二叉搜索树中的每个节点添加更大的值。因此,初始和最终的树将如下所示 -
算法
bstUpdate(root, sum) -
Begin if root is null, then stop bstUpdate(right of room, sum) sum := sum + value of root update root value using sum bstUpdate(left of room, sum) End登录后复制