You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/java/com/fishercoder/solutions/_979.java
+3-53
Original file line number
Diff line number
Diff line change
@@ -2,61 +2,11 @@
2
2
3
3
importcom.fishercoder.common.classes.TreeNode;
4
4
5
-
/**
6
-
* 979. Distribute Coins in Binary Tree
7
-
*
8
-
* Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and there are N coins total.
9
-
* In one move, we may choose two adjacent nodes and move one coin from one node to another. (The move may be from parent to child, or from child to parent.)
10
-
* Return the number of moves required to make every node have exactly one coin.
11
-
*
12
-
* Example 1:
13
-
*
14
-
* 3
15
-
* / \
16
-
* 0 0
17
-
*
18
-
* Input: [3,0,0]
19
-
* Output: 2
20
-
* Explanation: From the root of the tree, we move one coin to its left child, and one coin to its right child.
21
-
*
22
-
* Example 2:
23
-
*
24
-
* 0
25
-
* / \
26
-
* 3 0
27
-
*
28
-
* Input: [0,3,0]
29
-
* Output: 3
30
-
* Explanation: From the left child of the root, we move two coins to the root [taking two moves]. Then, we move one coin from the root of the tree to the right child.
0 commit comments