payal-kothari
7/19/2017 - 3:20 AM

must read From https://leetcode.com/problems/invert-binary-tree/#/description

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class Solution {
    public TreeNode invertTree(TreeNode root) {
        
        if (root == null){
            return null;
        }
        
        TreeNode newNode = new TreeNode(root.val);
        
        newNode.left = invertTree(root.right);
        newNode.right = invertTree(root.left);
        
        return newNode;
    }
}