public List<TreeNode> generateTrees(int n) {
        List<TreeNode>[] result = new List[n+1];
        result[0] = new ArrayList<TreeNode>();
        result[0].add(null);
        for(int i = 1; i <= n; i++){
            result[i] = new ArrayList<TreeNode>();
            for(int j = 0;j < i; j++){
                for(TreeNode nodeLeft : result[j])
                    for(TreeNode nodeRight : result[i - 1 - j]){
                        TreeNode node = new TreeNode(j+1);
                        node.left = nodeLeft;
                        node.right = reValClone(nodeRight,j+1);
                        result[i].add(node);
                    }
            }
        }
        return result[n];
    }