Input: root = [1, 2, 3, 4, 5, null, null]
Output: true
Exmplanation:
1/ \
23/ \
45This is a full binary tree as every node other than the leaves has two children.
Example 2:
1
2
3
4
5
6
7
8
9
Input: root = [1, 2, 3, 4, null, null, 5]
Output: false
Explanation:
1/ \
23/ \
45This isnot a full binary tree as the node with value 2 has only one child.
⏰ Time complexity: O(n), where n is the number of nodes in the tree since we need to visit each node once.
🧺 Space complexity: O(h), where h is the height of the tree. In the worst case (a skewed tree), the recursive stack will store all nodes in one path, resulting in O(n) space complexity.