Leetcode 226. Invert Binary Tree

Leetcode 226. Invert Binary Tree

Question: Given the root of a binary tree, invert the tree, and return its root.

Screenshot from 2022-09-24 19-26-52.png

class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null)
            return null;
        TreeNode ans = new TreeNode(root.val);
        ans.right = invertTree(root.left);
        ans.left = invertTree(root.right);
        return ans;
    }
}