recrusive java


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

Log in to reply
 

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