Skip to content

Commit a0d4548

Browse files
refactor 979
1 parent d97bac8 commit a0d4548

File tree

1 file changed

+3
-53
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-53
lines changed

src/main/java/com/fishercoder/solutions/_979.java

+3-53
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,11 @@
22

33
import com.fishercoder.common.classes.TreeNode;
44

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.
31-
*
32-
* Example 3:
33-
*
34-
* 0
35-
* / \
36-
* 1 2
37-
*
38-
* Input: [1,0,2]
39-
* Output: 2
40-
*
41-
* Example 4:
42-
*
43-
* 1
44-
* / \
45-
* 0 0
46-
* \
47-
* 3
48-
*
49-
* Input: [1,0,0,null,3]
50-
* Output: 4
51-
*
52-
*
53-
* Note:
54-
* 1<= N <= 100
55-
* 0 <= node.val <= N
56-
* */
575
public class _979 {
586
public static class Solution1 {
59-
/**credit: https://leetcode.com/problems/distribute-coins-in-binary-tree/discuss/221930/JavaC%2B%2BPython-Recursive-Solution*/
7+
/**
8+
* credit: https://leetcode.com/problems/distribute-coins-in-binary-tree/discuss/221930/JavaC%2B%2BPython-Recursive-Solution
9+
*/
6010
int moves = 0;
6111

6212
public int distributeCoins(TreeNode root) {

0 commit comments

Comments
 (0)