Analysis:
- You should use recursion and treat every three nodes as a group
- Then you can find that the left most node must be the root, then we return it as parent node
- remember to reset root’s left node and right node to NULL
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |