leetcode894
class Solution { private Map<Integer, List<TreeNode>> memo; public List<TreeNode> allPossibleFBT(int N) {
this.memo = new HashMap<>();
return backtrack(N);
} private List<TreeNode> backtrack(int n) {
List<TreeNode> ret = new ArrayList<>();
if (n < 1) {
return ret;
} if (n == 1) {
ret.add(new TreeNode(0));
return ret;
} if (memo.containsKey(n)) {
return memo.get(n);
} for (int i = 1; i < n; i++) {
for (TreeNode left : backtrack(i)) {
for (TreeNode right : backtrack(n - i - 1)) {
TreeNode node = new TreeNode(0);
node.left = left;
node.right = right;
ret.add(node);
}
}
} memo.put(n, ret);
return ret;
}
}
leetcode894的更多相关文章
- [Swift]LeetCode894. 所有可能的满二叉树 | All Possible Full Binary Trees
A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list of al ...
随机推荐
- Assembly Experiment9
用英文写太浪费时间了,而且书上的讲解对各种功能的英文原句少之又少,有空还是看龙书吧(不存在的) 实验1: 十六进制转换十进制 实验代码: ; 在屏幕上输出内存单元中的十进制两位数 assume cs: ...
- JAVA工具类-StrUtils
public class StrUtils { public static final String UTF_8 = "UTF-8"; /** * 去掉小数字符串后面无用的零 */ ...
- java 大数运算[转]
用JAVA 实现算术表达式(1234324234324 + 8938459043545)/5 + 343434343432.59845 因为JAVA语言中的long 定义的变量值的最大数受到限制,例如 ...
- Game Development Patterns and Best Practices (John P. Doran / Matt Casanova 著)
https://github.com/PacktPublishing/Game-Development-Patterns-and-Best-Practices https://github.com/m ...
- day10 while else continue break
a. while else b. continue break continue ,终止当前循环,开始下一次循环 break ...
- 简单的AOP标签
常用标签 1.1<aop:config> //作用 用于声明aop的配置 //配置:<aop:config></aop:config> 1.2 <aop:as ...
- 在Vue组件中获取全局的点击事件
// 定义全局点击函数 Vue.prototype.globalClick = function (callback) { document.getElementById('main').onclic ...
- SqlServer高版本数据备份还原到低版本(转)
原文地址:https://www.jb51.net/article/96454.htm 想要将Sqlserver2014高版本备份的数据还原到低版本SqlServer2008R2上去,但是这在SqlS ...
- WMware 中CentOS系统Hadoop 分布式环境搭建(一)——Hadoop安装环境准备
1.创建3台虚拟机并装好系统,这里使用64位CentOS. 2.Ping测试[确保两两能ping通]: [ping xxx.xxx.xxx.xxx] 3.安装SSH:[yum install ssh ...
- scrapy实战之scrapyrt的使用
scrapyrt为scrapy提供了一个http接口,有了它,我们不用再执行命令,而是直接请求一个http接口来启动项目,如果项目是部署在远程的,会比较方便. 1.安装: pip install sc ...