Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. // Runtime: 0 ms
  2. class Solution {
  3.     int moves;
  4.    
  5.     public int distributeCoins(TreeNode root) {
  6.         b(root);
  7.         return moves;
  8.     }
  9.    
  10.     private int b(TreeNode root){
  11.         if (root == null) return 0;
  12.    
  13.         root.val += b(root.left) + b(root.right) - 1;
  14.         moves += Math.abs(root.val);
  15.        
  16.         return root.val;
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement