My Java Solution

  • 4
    public TreeNode invertTree(TreeNode root) {
            if(root == null) return root;
            if(root.left==null && root.right==null) return root;
    		TreeNode temp = null;
    		root.left = invertTree(root.left);
    		root.right =invertTree(root.right);
    		temp = root.left;
    		root.left = root.right;
    		root.right = temp;
    		return root;

  • 0

    Nice job! Send your resume to Google!

Log in to reply

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