Can we do it better than this?


  • 0
    M

    I feel it is lot intuitive that almost everyone follows the same approach

    public class Solution {
        public TreeNode invertTree(TreeNode root) {
            if( root == null )
                return root;
            TreeNode temp = root.right;
            root.right = root.left;
            root.left = temp;
            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.