Problem
Invert a binary tree.
Example
Input:
1 | 4 |
Output:
1 | 4 |
Solution1
Method: Recursive
Time Complexity:
Space Complexity:
1 | # Definition for a binary tree node. |
Solution2
Method: Depth First Search
Time Complexity: O(n)
Space Complexity: O(n)
1 | # Definition for a binary tree node. |
or
1 | # Definition for a binary tree node. |
Solution3
Method: Breadth First Search
Time Complexity: O(n)
Space Complexity: O(n)
1 | # Definition for a binary tree node. |