Leetcode 894. All Possible Full Binary Trees
递归
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
import functools
class Solution:
@functools.lru_cache()
def allPossibleFBT(self, N: int) -> List[TreeNode]:
ans=[]
if N==1:
return [TreeNode(0)] for i in range(0,N):
if (i==0 or i%2==1) and ((N-1-i)==0 or (N-1-i)%2==1):
print(i,N-1-i)
for l in self.allPossibleFBT(i):
for r in self.allPossibleFBT(N-1-i):
root=TreeNode(0)
root.left=l
root.right=r
ans.append(root)
else:
continue return ans
Leetcode 894. All Possible Full Binary Trees的更多相关文章
- [LeetCode] 894. 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 ...
- 【LeetCode】894. All Possible Full Binary Trees 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【LeetCode】951. Flip Equivalent Binary Trees 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...
- 【LeetCode】617. Merge Two Binary Trees 解题报告
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...
- leetcode第一天-merge two binary trees
有段时间没有写代码了,脑子都生锈了,今后争取笔耕不辍(立flag,以后打脸) 随机一道Leecode题, Merge Two Binary Trees,题目基本描述如下: Given two bina ...
- 113th LeetCode Weekly Contest Flip Equivalent Binary Trees
For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...
- 【leetcode】617. Merge Two Binary Trees
原题 Given two binary trees and imagine that when you put one of them to cover the other, some nodes o ...
- LC 894. 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 ...
- 【leetcode】951. Flip Equivalent Binary Trees
题目如下: For a binary tree T, we can define a flip operation as follows: choose any node, and swap the ...
随机推荐
- 20135320赵瀚青LINUX第一章读书笔记
第一章-Linux内核简介 Unix的历史 依旧被认为是最强大和最优秀的系统 由一个失败的操作系统Multics中产生 被移植到PDP-11型机中 由其他组织进一步开发 重写了虚拟内存系统,最终官方版 ...
- Hive的执行生命周期
1.入口$HIVE_HOME/bin/ext/cli.sh 调用org.apache.hadoop.hive.cli.CliDriver类进行初始化过程 处理-e,-f,-h等信息,如果是-h,打印提 ...
- JAVA基础补漏--List
Arraylist 通过对ArrayList的源码的查看,他的底层实现是对数组进行数据的操作,所以他的数据特点同数组. 查询快,因为他的内存区域为一个整块,可直接根据索引进行查询. 增删慢,因为每次增 ...
- [Network Architecture]Mask R-CNN论文解析(转)
前言 最近有一个idea需要去验证,比较忙,看完Mask R-CNN论文了,最近会去研究Mask R-CNN的代码,论文解析转载网上的两篇博客 技术挖掘者 remanented 文章1 论文题目:Ma ...
- jQuery编程规范与最佳实践(附带一些个人的笔记)
加载jQuery-Loading jQuery 1.坚持使用CDN来加载jQuery,这种别人服务器免费帮你托管文件的便宜干嘛不占呢.点击查看使用CDN的好处,点此查看一些主流的jQuery CDN地 ...
- NSMutableString和NSString区别,及相互转换方法
NSString是一个不可变的字符串对象.这不是表示这个对象声明的变量的值不可变,而是表示它初始化以后,你不能改变该变量所分配的内存中的值,但你可以重新分配该变量所处的内存空间.而NSMutableS ...
- Nordic官方网络资源介绍(官网/devzone/GitHub)
本文将介绍Nordic官方网络资源,包括Nordic官网,开发者论坛(devzone),以及Nordic在GitHub上的共享资源. 1. Nordic官网(产品/SDK/工具/文档库) Nordic ...
- ItemsControl的ItemContainerStyle属性
ItemsControl:ListBox,ComboBox,TreeView ItemContainerStyle是用来设置每一个集合控件的Item的样式的属性(即设置每一个项的样式). 使用It ...
- 项目使用文档管理:MediaWiki安装及使用入门
MediaWiki是著名的开源wiki引擎,全球最大的wiki项目维基百科(百科词条协作系统)是使用MediaWiki的成功范例,MediaWiki的最大作用在于对知识的归档,可用于构建企业/个人知识 ...
- 1029: [JSOI2007]建筑抢修 贪心
https://www.lydsy.com/JudgeOnline/problem.php?id=1029 题意:n个建筑,每个有修复时间和爆炸时间,没有在爆炸时间内修复就会爆炸,问最多能修复的建筑 ...