Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- Map<TreeNode, Integer> balance;
- int moves;
- public int distributeCoins(TreeNode root) {
- count(root);
- normalize(root);
- return moves;
- }
- private void normalize(TreeNode root) {
- if (root == null) return;
- normalize(root.left);
- normalize(root.right);
- }
- private void count(TreeNode root) {
- if (root == null) return;
- counts.put(root, root.val - 1 + count(root.left) + count(root.right));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement