- invert the tree:
- swap a nodes left child with its right child
π‘ Explanation of Solution
DFS, recursively check the left and right subtrees until we reach a leaf node
- create a temp node and perform the swap of the leaf node's children
- recurse up the call stack until all swaps have been performed
β Complexity Analysis
Time Complexity: O(n)
- DFS traversal visiting each node a single time
Space Complexity: O(log n) to O(n) depending on balance of the tree due to use of recursive call stack