|
5 | 5 | importjava.util.ArrayList;
|
6 | 6 | importjava.util.List;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * Source: https://leetcode.com/problems/sum-of-root-to-leaf-binary-numbers/ |
10 |
| - * |
11 |
| - * 1022. Sum of Root To Leaf Binary Numbers |
12 |
| - * |
13 |
| - * Given a binary tree, each node has value 0 or 1. Each root-to-leaf path represents a binary number starting with the most significant bit. For example, if the path is 0 -> 1 -> 1 -> 0 -> 1, then this could represent 01101 in binary, which is 13. |
14 |
| - * |
15 |
| - * For all leaves in the tree, consider the numbers represented by the path from the root to that leaf. |
16 |
| - * |
17 |
| - * Return the sum of these numbers. |
18 |
| - * |
19 |
| - * Example 1: |
20 |
| - * |
21 |
| - * 1 |
22 |
| - * / \ |
23 |
| - * 0 1 |
24 |
| - * / \ / \ |
25 |
| - * 0 1 0 1 |
26 |
| - * |
27 |
| - * Input: [1,0,1,0,1,0,1] |
28 |
| - * Output: 22 |
29 |
| - * Explanation: (100) + (101) + (110) + (111) = 4 + 5 + 6 + 7 = 22 |
30 |
| - * |
31 |
| - * Note: |
32 |
| - * |
33 |
| - * The number of nodes in the tree is between 1 and 1000. |
34 |
| - * node.val is 0 or 1. |
35 |
| - * The answer will not exceed 2^31 - 1. |
36 |
| - * */ |
37 | 8 | publicclass_1022 {
|
38 | 9 | publicstaticclassSolution1 {
|
39 | 10 | publicintsumRootToLeaf(TreeNoderoot) {
|
|