Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Runtime: 0 ms
- class Solution {
- int moves;
- public int distributeCoins(TreeNode root) {
- b(root);
- return moves;
- }
- private int b(TreeNode root){
- if (root == null) return 0;
- root.val += b(root.left) + b(root.right) - 1;
- moves += Math.abs(root.val);
- return root.val;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement