Analysis:
Use in-order traversal to find the disorder node pairs.
- If there is one pair: that means the swap nodes are adjacent.
- If ther are two pair: they are not next to each other.
Finally swap them by value. This is not the optimal solution. BTW
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |