222. Count Complete Tree Nodes ¶
Approach 1: Naive¶
- Time: $O(n)$
- Space: $O(h)$
1 2 3 4 5 6 7 8 |
|
1 2 3 4 5 6 7 |
|
1 2 3 4 5 |
|
Approach 2: Heuristic¶
- Time: $O(\log^2n)$
- Space: $O(h)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|