/**
 @author Farheen Bano
  
 References-
 https://www.geeksforgeeks.org/write-an-efficient-c-function-to-convert-a-tree-into-its-mirror-tree/
 https://leetcode.com/problems/invert-binary-tree/
*/

import java.util.*;
import java.lang.*;
import java.io.*;

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public TreeNode invertTree(TreeNode root) {
        return invert(root);

    }
    
    public TreeNode invert(TreeNode root){
        if(root==null)
            return root;
        
        TreeNode left=invert(root.left);
        TreeNode right=invert(root.right);
        
        root.left=right;
        root.right=left;
        return root;

    }
}
