Distribute Coins in Binary Tree LeetCode solution in Java
1class Solution {2int count = 0;34public int helper(TreeNode root) {5if (root == null) return 0;6int left = helper(root.left);7int right = helper(root.right);8count += Math.abs(left) + Math.abs(right);9return (left + right + root.val - 1);10}1112public int distributeCoins(TreeNode root) {13helper(root);14return count;15}16}