|
6 | 6 | import java.util.LinkedList;
|
7 | 7 | import java.util.List;
|
8 | 8 |
|
9 |
| -/** |
10 |
| - * 655. Print Binary Tree |
11 |
| - * |
12 |
| - * Print a binary tree in an m*n 2D string array following these rules: |
13 |
| - * 1. The row number m should be equal to the height of the given binary tree. |
14 |
| - * 2. The column number n should always be an odd number. |
15 |
| - * 3. The root node's value (in string format) should be put in the exactly middle of the first row it can be put. |
16 |
| - * The column and the row where the root node belongs will separate the rest space into two parts (left-bottom part and right-bottom part). |
17 |
| - * You should print the left subtree in the left-bottom part and print the right subtree in the right-bottom part. |
18 |
| - * The left-bottom part and the right-bottom part should have the same size. |
19 |
| - * Even if one subtree is none while the other is not, |
20 |
| - * you don't need to print anything for the none subtree but |
21 |
| - * still need to leave the space as large as that for the other subtree. |
22 |
| - * However, if two subtrees are none, then you don't need to leave space for both of them. |
23 |
| - * 4. Each unused space should contain an empty string "". |
24 |
| - * 5. Print the subtrees following the same rules. |
25 |
| -
|
26 |
| - Example 1: |
27 |
| - Input: |
28 |
| - 1 |
29 |
| - / |
30 |
| - 2 |
31 |
| - Output: |
32 |
| - [["", "1", ""], |
33 |
| - ["2", "", ""]] |
34 |
| -
|
35 |
| - Example 2: |
36 |
| - Input: |
37 |
| - 1 |
38 |
| - / \ |
39 |
| - 2 3 |
40 |
| - \ |
41 |
| - 4 |
42 |
| - Output: |
43 |
| - [["", "", "", "1", "", "", ""], |
44 |
| - ["", "2", "", "", "", "3", ""], |
45 |
| - ["", "", "4", "", "", "", ""]] |
46 |
| -
|
47 |
| - Example 3: |
48 |
| - Input: |
49 |
| - 1 |
50 |
| - / \ |
51 |
| - 2 5 |
52 |
| - / |
53 |
| - 3 |
54 |
| - / |
55 |
| - 4 |
56 |
| - Output: |
57 |
| -
|
58 |
| - [["", "", "", "", "", "", "", "1", "", "", "", "", "", "", ""] |
59 |
| - ["", "", "", "2", "", "", "", "", "", "", "", "5", "", "", ""] |
60 |
| - ["", "3", "", "", "", "", "", "", "", "", "", "", "", "", ""] |
61 |
| - ["4", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]] |
62 |
| -
|
63 |
| - Note: The height of binary tree is in the range of [1, 10] |
64 |
| - */ |
65 | 9 | public class _655 {
|
66 | 10 |
|
67 | 11 | public static class Solution1 {
|
|
0 commit comments