|
5 | 5 | importjava.util.LinkedList;
|
6 | 6 | importjava.util.Queue;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * 958. Check Completeness of a Binary Tree |
10 |
| - * |
11 |
| - * Given a binary tree, determine if it is a complete binary tree. |
12 |
| - * Definition of a complete binary tree from Wikipedia: |
13 |
| - * In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. |
14 |
| - * It can have between 1 and 2h nodes inclusive at the last level h. |
15 |
| - * |
16 |
| - * Example 1: |
17 |
| - * 1 |
18 |
| - * / \ |
19 |
| - * 2 3 |
20 |
| - * / \ / |
21 |
| - * 4 5 6 |
22 |
| - * |
23 |
| - * Input: [1,2,3,4,5,6] |
24 |
| - * Output: true |
25 |
| - * Explanation: Every level before the last is full (ie. levels with node-values {1} and {2, 3}), |
26 |
| - * and all nodes in the last level ({4, 5, 6}) are as far left as possible. |
27 |
| - * |
28 |
| - * Example 2: |
29 |
| - * 1 |
30 |
| - * / \ |
31 |
| - * 2 3 |
32 |
| - * / \ \ |
33 |
| - * 4 5 7 |
34 |
| - * Input: [1,2,3,4,5,null,7] |
35 |
| - * Output: false |
36 |
| - * Explanation: The node with value 7 isn't as far left as possible. |
37 |
| - * |
38 |
| - * Note: |
39 |
| - * The tree will have between 1 and 100 nodes. |
40 |
| - * */ |
41 | 8 | publicclass_958 {
|
42 | 9 | publicstaticclassSolution1 {
|
43 | 10 | publicbooleanisCompleteTree(TreeNoderoot) {
|
|