Distribute Coins in Binary Tree LeetCode solution in JavaScript
1var distributeCoins = function (root) {2var moves = 0;3postorder(root);4return moves;56function postorder(node) {7if (!node) return 0;89const subTotal = postorder(node.left) + postorder(node.right);10const result = node.val - 1 + subTotal;11moves += Math.abs(result);1213return result;14}15};