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 ...
随机推荐
- struts1.2上传多个文件
页面: <input type="file" name="impFile[0]" style="wid ...
- [BZOJ4003]城池攻占
Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖, ...
- intellij 文件太大,无法code assistant
添加 idea.max.intellisense.filesize=2500 在IDE_HOME\bin\idea.properties https://intellij-support.jetbra ...
- 搭建ODS的几套解决方案对比
公司业务,想要搭建一个医院的ODS服务器:将医院不同厂家的不同数据库版本数据库类型整到一台服务器中,最初想要是同步数据库原生同步机制,最理想的是sqlserver发布订阅,但是后来发现发布订阅不能发布 ...
- Harbor 定制页面 和 二次开发指南
harbor的官方地址:https://github.com/goharbor/harbor 想对Harbor进行二次开发,首先要指定一个harbor的版本,这里我们以Harbor:1.6.2为例: ...
- php入门(一)
一,在HTML中嵌入php代码 先看html的代码: <form action="processorder.php" method="post"> ...
- mysql中索引利用情况(explain用法)
使用explain查看,如下 1.首先创建表test,语句如下 create table test(a int,b varchar(10),c varchar(10)); 2.在表中的a,b都创建索引 ...
- jquery阻止冒泡和阻止默认事件
event.stopPropagation(); event.preventDefault(); http://www.cnblogs.com/qixuejia/archive/2013/10/10/ ...
- java, double转String, 去掉0结尾的小数位
小问题:double值的小数位是0时,转String会有“.0”结尾.比如,double值是“12”,转String得到的字符串是“12.0”.如果需要去掉0结尾的小数位,应当如何解决呢? 解决方案: ...
- WebAPI项目 IHttpActionResult不识别解决办法
转自:http://blog.csdn.net/nnnnnbody/article/details/16945253 使用ASP.NET Web API构造基于restful风格web service ...