File tree 1 file changed +4
-43
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +4
-43
lines changed Original file line number Diff line number Diff line change 5
5
import java .util .HashMap ;
6
6
import java .util .Map ;
7
7
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
- */
49
8
public class _666 {
50
9
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
+ */
53
14
public int totalSum = 0 ;
54
15
55
16
public int pathSum (int [] nums ) {
You can’t perform that action at this time.
0 commit comments