递归

# 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的更多相关文章

  1. [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 ...

  2. 【LeetCode】894. All Possible Full Binary Trees 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  3. 【LeetCode】951. Flip Equivalent Binary Trees 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...

  4. 【LeetCode】617. Merge Two Binary Trees 解题报告

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...

  5. leetcode第一天-merge two binary trees

    有段时间没有写代码了,脑子都生锈了,今后争取笔耕不辍(立flag,以后打脸) 随机一道Leecode题, Merge Two Binary Trees,题目基本描述如下: Given two bina ...

  6. 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 ...

  7. 【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 ...

  8. 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 ...

  9. 【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 ...

随机推荐

  1. MR案例:Reduce-Join

    问题描述:两种类型输入文件:address(地址)和company(公司)进行一对多的关联查询,得到地址名(例如:Beijing)与公司名(例如:Beijing JD.Beijing Red Star ...

  2. Eclipse FindBugs插件

    在线安装: Update Site:http://findbugs.cs.umd.edu/eclipse 本地安装: 1.首先从findbugs网站下载插件:http://findbugs.sourc ...

  3. [BZOJ2109]Plane 航空管制

    Description 世博期间,上海的航空客运量大大超过了平时,随之而来的航空管制也频频 发生.最近,小X就因为航空管制,连续两次在机场被延误超过了两小时.对此, 小X表示很不满意. 在这次来烟台的 ...

  4. nfs报错 - No route to host

    nfs报错 - No route to host ______________________________ 因为防火墙阻止的原因. 解决方法:服务器rhel7系统下,打开firewall-conf ...

  5. LeetCode——Find Minimum in Rotated Sorted Array II

    Question Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allo ...

  6. HTTP-API-DESIGN 怎样设计一个合理的 HTTP API (二)

    接上篇 HTTP-API-DESIGN 怎样设计一个合理的 HTTP API (一) 整个 ppt 可以去这里下载. 这一篇主要从服务端应该如何返回合理的返回值的角度,讨论如何设计一个合理的 HTTP ...

  7. hdu 4857 逃生 拓扑排序+逆向建图

    逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Descr ...

  8. 【Linux】无法添加用户,报“useradd: cannot open /etc/passwd”问题解决过程记录

    问题描述 今天在一个新的Linux环境添加用户的时候,发现不能添加,遇到了以下错误 useradd: cannot open /etc/passwd 解决方法 用lsattr命令查看/etc/pass ...

  9. HTML5 history API,创造更好的浏览体验

    HTML5 history API有什么用呢? 从Ajax翻页的问题说起 请想象你正在看一个视频下面的评论,在翻到十几页的时候,你发现一个写得稍长,但非常有趣的评论.正当你想要停下滚轮细看的时候,手残 ...

  10. Angular单元测试系列

    Angular单元测试系列 - 大纲Angular单元测试系列 - 简介Angular单元测试系列 - 如何使用Jasmine进行Angular单元测试Angular单元测试系列 - Router.C ...