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 ...
随机推荐
- Socket 是嘛玩意儿(简单聊聊)
网络上的两个程序通过一个双向的通信连接实现数据的交换,这个连接的一端称为一个socket. 建立网络通信连接至少要一对端口号(socket).socket本质是编程接口(API),对TCP/IP的封装 ...
- Jenkins 集成Ansible教程
前提条件: 1. 部署Jenkins Server 2. 部署 Ansible Server 一.在Jenkins安装SSH插件 系统管理 -> 插件管理 二.在Jenkins 凭证中添加Ans ...
- spark SQL学习(案例-统计每日uv)
需求:统计每日uv package wujiadong_sparkSQL import org.apache.spark.sql.{Row, SQLContext} import org.apache ...
- sql 取前一年、月
SQL SERVER 提供了一些时间函数:取当前时间:SELECT GETDATE() 取前一个月的时间:SELECT DATEADD(MONTH,-1,GETDATE()) 月份减一个月取年份:SE ...
- git拉取GitLab工程报错Repository not found
# git clone http://xxx/jiqing/frog.git 正克隆到 'frog'... fatal: repository 'http://xxx/jiqing/frog.git/ ...
- 数据可视化——Matplotlib(1)
导入相关模块 import matplotlib.pyplot as plt import pandas as pd import numpy as np 基本图表 散点图:scatter N = 1 ...
- JAVA8 HashMap 源码阅读
序 阅读java源码可能是每一个java程序员的必修课,只有知其所以然,才能更好的使用java,写出更优美的程序,阅读java源码也为我们后面阅读java框架的源码打下了基础.阅读源代码其实就像再看一 ...
- 字符串与byte[]之间的转换
一. 编码 同一个字符在不同的编码下会被编成不同长度的编码,比如: ACSII,每个字符对应一个字节,实际上只使用了7位,从00h-7Fh.只能表达128个字符. GB2312,中文的一种编码,每个 ...
- poi 取excel单元格内容时,需要判断单元格的类型,才能正确取出
以下内容非原创,原文链接http://blog.sina.com.cn/s/blog_4b5bc01101015iuq.html ate String getCellValue(HSSFCell ce ...
- 工作流引擎Activiti使用总结(转)
1.简单介工作流引擎与Activiti 对于工作流引擎的解释请参考百度百科:工作流引擎 1.1 我与工作流引擎 在第一家公司工作的时候主要任务就是开发OA系统,当然基本都是有工作流的支持,不过当时使用 ...