Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0d4548

Browse files
refactor 979
1 parentd97bac8 commita0d4548

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

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,11 @@
22

33
importcom.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
publicclass_979 {
586
publicstaticclassSolution1 {
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
intmoves =0;
6111

6212
publicintdistributeCoins(TreeNoderoot) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp