码迷,mamicode.com
首页 >  
搜索关键字:trees    ( 1351个结果
leetcode 872. 叶子相似的树(Leaf-Similar Trees)
[TOC] 题目描述: 请考虑一颗二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 。 举个例子,如上图所示,给定一颗叶值序列为 的树。 如果有两颗二叉树的叶值序列是相同,那么我们就认为它们是 叶相似 的。 如果给定的两个头结点分别为 和 的树是叶相似的,则返回 ;否则返回 。 ...
分类:其他好文   时间:2019-04-06 23:07:54    阅读次数:158
Dichromatic Trees
条件: 1:每个红色节点的儿子都是黑色节点 2.每个叶子到根路径上的黑点数相等,等于某个常数,称作树的black height 求给定black height和节点数的符合条件的方案数 $black_{h} = x (black_{h-1} + red_{h-1})^2$ $red_{h} = x ...
分类:其他好文   时间:2019-04-05 11:56:30    阅读次数:124
codeforces431C
k-Tree CodeForces - 431C Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tre ...
分类:其他好文   时间:2019-04-03 22:12:45    阅读次数:157
C. Edgy Trees Codeforces Round #548 (Div. 2) 并查集求连通块
C. Edgy Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output C. Edgy Trees time limit p ...
分类:其他好文   时间:2019-03-31 09:43:22    阅读次数:204
【leetcode】572. Subtree of Another Tree
题目如下: Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of  ...
分类:其他好文   时间:2019-03-23 22:47:38    阅读次数:151
Codeforces Round #369 (Div. 2)
C. Coloring Trees O(n^4)暴力DP就好了 D. Directed Roads 每个点出度为1, 那么图是一个基环树森林, 再观察一下可以发现答案为$2^n-2^(环的数量+非环边数)$ ...
分类:其他好文   时间:2019-03-23 22:11:54    阅读次数:153
Leetcode 617. Merge Two Binary Trees
import functools class Solution(object): @functools.lru_cache() def mergeTrees(self, t1, t2): if t1 and t2: root = TreeNode(t1.val + t2.val) root.left... ...
分类:其他好文   时间:2019-03-23 18:39:18    阅读次数:129
leetcode_894. All Possible Full Binary Trees
https://leetcode.com/problems/all-possible-full-binary-trees/ 给定节点个数,求所有可能二叉树,该二叉树所有节点要么有0个子节点要么有两个子节点。返回所有二叉树的头指针。 一开始一直想的是从根节点开始建树,一直想不出来方法。后来想到可以从子 ...
分类:其他好文   时间:2019-03-23 10:38:04    阅读次数:129
ZOJ-1167-Trees on the Level
题解: 我的解法是用一个类似字典树结构的结构体来表示节点。看到另一种解法是用数组来映射二叉树的,开到14000就过了,但是我觉得是数据水了,因为题中说最多 256个节点,如果256个节点连成链型,除根节点外每个节点都是父节点的右儿子。那么数组要开pow(2, 256)个。可见这种方法是不可行的; 类 ...
分类:其他好文   时间:2019-03-22 11:47:44    阅读次数:127
leetcode 894. 所有可能的满二叉树(All Possible Full Binary Trees)
题目 满二叉树是一类二叉树,其中每个结点恰好有 0 或 2 个子结点。 返回包含 N 个结点的所有可能满二叉树的列表。 答案的每个元素都是一个可能树的根结点。 答案中每个树的每个结点都必须有 node.val=0。 你可以按任何顺序返回树的最终列表。 示例: 输入:7输出:[[0,0,0,null, ...
分类:其他好文   时间:2019-03-20 01:02:39    阅读次数:198
1351条   上一页 1 ... 13 14 15 16 17 ... 136 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!