Easy recursive solution (JAVA)


  • 4
    public class Solution {
        public TreeNode invertTree(TreeNode root) {
            if(root != null){
                TreeNode left = root.left;
                root.left = root.right;
                root.right = left;
                invertTree(root.left);
                invertTree(root.right);
            }
            return root;
        }
    }

Log in to reply
 

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