Analysis:
Search the left most and right most node, if the depth of them are the same, then it means that
this is a complete binary tree (subtree).
Otherwise, traverse through the subtrees
Time Complexity:
- O(logn^2)
Space Complexity:
- O(n)
Code
1 | # Definition for a binary tree node. |