[JAVA] DFS post order / O : T(N), S : O(logN) or O(1)


  • 0
    J
    public class Solution {
        public TreeNode invertTree(TreeNode root) {
            if(root == null)
                return null;
            
            invertTree(root.left);
            invertTree(root.right);
            
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
            
            return root;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.