码迷,mamicode.com
首页 >  
搜索关键字:binary tree upside d    ( 23249个结果)
129. Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 whic ...
分类:其他好文   时间:2020-02-07 10:41:25    阅读次数:56
CSP-J/S2019试题选做
小蒟蒻duyi CSP爆炸之后一直在颓,所以直到最近才陆续订正完CSP的题/kel 以后不能这么颓了(flag) S D1T2 括号树 设$f[u]$表示根到$u$的路径上有多少子串是合法括号串。(即题目里的$k_u$,此变量名缺乏个性,故换之) 从根向每个节点dfs,容易求出$c[u]$:表示从根 ...
分类:其他好文   时间:2020-02-07 10:23:39    阅读次数:93
938. Range Sum of BST
Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is g ...
分类:其他好文   时间:2020-02-07 10:19:29    阅读次数:70
[leetcode]Fruit Into Baskets
滑动窗口,原来可以通过循环嵌套循环的方式实现。 class Solution: def totalFruit(self, tree: List[int]) -> int: result = 0 fruitDict = {} i = 0 # assert i <= j for j in range(l ...
分类:其他好文   时间:2020-02-07 01:24:30    阅读次数:64
【PAT甲级】1110 Complete Binary Tree (25分)
题意: 输入一个正整数N(<=20),代表结点个数(0~N-1),接着输入N行每行包括每个结点的左右子结点,'-'表示无该子结点,输出是否是一颗完全二叉树,是的话输出最后一个子结点否则输出根节点。 trick: 用char输入子结点没有考虑两位数的结点😓。。。 stoi(x)可以将x转化为十进制整 ...
分类:其他好文   时间:2020-02-07 00:59:15    阅读次数:72
red-black tree
一颗红黑树是满足下面红黑性质的二叉搜索树 ①每个结点或是红的,或是黑的。 ②根结点是黑的 ③每个叶结点(NIL)是黑的 ④如果一个结点是红色的,则它的两个子结点是黑色的。 ⑤对每个结点,从该结点到其所有后代叶结点的简单路径上,均包含相同数目的黑色结点。 插入时总是要考虑它的叔叔,删除时总要考虑它的兄 ...
分类:其他好文   时间:2020-02-06 23:23:32    阅读次数:80
「CF662C」 Binary Table
「CF662C」 Binary Table "题目链接" 题目所给的 $n$ 很小,于是我们可以考虑这样一种朴素做法:暴力枚举第 $i$ 行是否翻转,这样每一行的状态就确定了,这时取每一列 $0/1$ 个数较小的数字即可(因为每一列也可以翻转)。这样的时间复杂度是 $O(m\cdot2^n)$。 但 ...
分类:其他好文   时间:2020-02-06 19:44:38    阅读次数:62
题解 SP375 【QTREE - Query on a tree】
$$ \texttt{Preface} $$ 这题在 $\text{Luogu}$ 上竟然不能交 $C++$ ,会一直 $Waiting$ ,只能交非 $C++$ 的语言。 所以打完了 $C++$ 要转到 $C$ 才能过。 要把什么 $swap$ , $max$ 各种函数换成手写,以及 $C++$ ...
分类:其他好文   时间:2020-02-06 12:49:37    阅读次数:42
LeetCode#476 Number Complement - in Swift
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.給一個正整數,算出他的二補數 (2’s c... ...
分类:编程语言   时间:2020-02-06 12:32:52    阅读次数:77
865. Smallest Subtree with all the Deepest Nodes
Given a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the largest depth possibl ...
分类:其他好文   时间:2020-02-06 11:07:31    阅读次数:74
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!