LeetCode #: 1145
Difficulty: Medium.
Topics: Tree, depth-first search.
In the best case, the solution will visit ((n / 2) + 1)
nodes.
In the worst case, the solution will visit each node once.
The extra space used is always the same regardless of n
.