Skip to content

Commit 71af3d0

Browse files
refactor 666
1 parent 54b3bbf commit 71af3d0

File tree

1 file changed

+4
-43
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-43
lines changed

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

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,12 @@
55
import java.util.HashMap;
66
import java.util.Map;
77

8-
/**
9-
* 666. Path Sum IV
10-
* If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digits integers.
11-
12-
For each integer in this list:
13-
14-
The hundreds digit represents the depth D of this node, 1 <= D <= 4.
15-
16-
The tens digit represents the position P of this node in the level it belongs to, 1 <= P <= 8.
17-
The position is the same as that in a full binary tree.
18-
19-
The units digit represents the value V of this node, 0 <= V <= 9.
20-
21-
Given a list of ascending three-digits integers representing a binary with the depth smaller than 5.
22-
You need to return the totalSum of all paths from the root towards the leaves.
23-
24-
Example 1:
25-
26-
Input: [113, 215, 221]
27-
Output: 12
28-
Explanation:
29-
The tree that the list represents is:
30-
3
31-
/ \
32-
5 1
33-
34-
The path totalSum is (3 + 5) + (3 + 1) = 12.
35-
36-
Example 2:
37-
38-
Input: [113, 221]
39-
Output: 4
40-
Explanation:
41-
The tree that the list represents is:
42-
3
43-
\
44-
1
45-
46-
The path totalSum is (3 + 1) = 4.
47-
48-
*/
498
public class _666 {
509
public static class Solution1 {
51-
/**OMG, since it's no larger than depth 5, I've got a hardcoded solution here....
52-
* By "harcoded", I mean the constructTree() method.*/
10+
/**
11+
* OMG, since it's no larger than depth 5, I've got a hardcoded solution here....
12+
* By "harcoded", I mean the constructTree() method.
13+
*/
5314
public int totalSum = 0;
5415

5516
public int pathSum(int[] nums) {

0 commit comments

Comments
 (0)