You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a `n * n` matrix `grid` of `0's` and `1's` only. We want to represent
@@ -13,42 +12,26 @@ Return _the root of the Quad-Tree representing_`grid`.
13
12
A Quad-Tree is a tree data structure in which each internal node has exactly
14
13
four children. Besides, each node has two attributes:
15
14
16
-
*`val`: True if the node represents a grid of 1's or False if the node represents a grid of 0's. Notice that you can assign the `val` to True or False when `isLeaf` is False, and both are accepted in the answer.
17
-
*`isLeaf`: True if the node is a leaf node on the tree or False if the node has four children.
18
-
19
-
>
20
-
>
21
-
>
22
-
>
23
-
>
24
-
> class Node {
25
-
>
26
-
> >
27
-
> public boolean val;
28
-
>
29
-
> >
30
-
> public boolean isLeaf;
31
-
>
32
-
> >
33
-
> public Node topLeft;
34
-
>
35
-
> >
36
-
> public Node topRight;
37
-
>
38
-
> >
39
-
> public Node bottomLeft;
40
-
>
41
-
> >
42
-
> public Node bottomRight;
43
-
>
44
-
> }
15
+
-`val`: True if the node represents a grid of 1's or False if the node represents a grid of 0's. Notice that you can assign the `val` to True or False when `isLeaf` is False, and both are accepted in the answer.
16
+
-`isLeaf`: True if the node is a leaf node on the tree or False if the node has four children.
17
+
18
+
```
19
+
class Node {
20
+
public boolean val;
21
+
public boolean isLeaf;
22
+
public Node topLeft;
23
+
public Node topRight;
24
+
public Node bottomLeft;
25
+
public Node bottomRight;
26
+
}
27
+
```
45
28
46
29
We can construct a Quad-Tree from a two-dimensional area using the following
47
30
steps:
48
31
49
-
1. If the current grid has the same value (i.e all `1's` or all `0's`) set `isLeaf` True and set `val` to the value of the grid and set the four children to Null and stop.
50
-
2. If the current grid has different values, set `isLeaf` to False and set `val` to any value and divide the current grid into four sub-grids as shown in the photo.
51
-
3. Recurse for each of the children with the proper sub-grid.
32
+
1. If the current grid has the same value (i.e all `1's` or all `0's`) set `isLeaf` True and set `val` to the value of the grid and set the four children to Null and stop.
33
+
2. If the current grid has different values, set `isLeaf` to False and set `val` to any value and divide the current grid into four sub-grids as shown in the photo.
34
+
3. Recurse for each of the children with the proper sub-grid.
0 commit comments