Divide & Conquer of JAVA


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

Log in to reply
 

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