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 ...
随机推荐
- C++ operator 学习
1.概述 1.1what operator 是c++的一个关键字,和运算符如(=)一起使用,表示一个运算符重载函数 1.2why 对于C++提供的所有操作符,通常只支持对于基本数据类型和标准库中提供的 ...
- 迁移32位下的旧代码到64位sever遇到过的两个很诡异的问题
一个是GetHashCode,这个方法是返回一个int值,在32位系统里,都是正值,但在64位系统里会返回负值. 另一个问题是DataTable的Sort属性,在没有显示写明升序或降序的情况下,在32 ...
- centos7 升级openssh到openssh-8.0p1版本
环境介绍 centos7.3和centos7.6升级完毕测试登录ssh以及重启后登录ssh均无问题. 前期请自行配置好yum源(如果不会请百度) 整个过程不需要卸载原先的openssl包和openss ...
- http://blog.csdn.net/u012905422/article/details/53340260
轉自:http://blog.csdn.net/u012905422/article/details/53340260 对于python2.7版本,很多教程(如http://stackoverflow ...
- siftflow-fcn32s训练及预测
一.说明 SIFT Flow 是一个标注的语义分割的数据集,有两个label,一个是语义分类(33类),另一个是场景标签(3类). Semantic and geometric segmentatio ...
- 【CentOS】自定义服务添加
1.创建服务需要执行的脚本 cd /sb/scripts vi td-agent-testlog #!/bin/bash # # /etc/rc.d/init.d/td-agent-DC01 # # ...
- Linux运维小知识
自己日常用到的命令稍微备份一下: 版本确认 CentOS / RedHat Enterprise cat /etc/redhat-release Ubuntu cat /etc/lsb-release ...
- nice team小组出山啦!(第二次会议)
为什么niceteam小组一个月没有更新博客?因为我们正在埋头苦干.是的过去的一个月我们的小组成员正沉浸在知识的海洋中,今天是我们出山的好日子,特地记录一下我们的工作进度. 在项目经理的安排下,我们小 ...
- android 版本号大小比较
https://www.jianshu.com/p/ee1990270ee1 网上找了很多方法都不太靠谱,有问题,自己改了改,亲试可以 大家都知道,版本号一般由以下几部分组成: 1. 主版本号 2. ...
- git --- 持续更新
东转西转 git 1 git 使用 1.1 git 安装 ~$: sudo apt-get install git 1.2 git 初始化 ~$: git init ~$: git remote ad ...