5 lines simple java recursion code


  • 0
    D
    public class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null) return root;
        TreeNode tmp = root.left;
        root.left = invertTree(root.right);
        root.right = invertTree(tmp);
        return root;        
    }}

  • 0
    Z

    8 lines :):):):):)


Log in to reply
 

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