<两棵树的操作技巧> 题目 给定两个二叉树,编写一个函数来检验它们是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 示例 1: 输入: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1,2,3] 输出: true 示例 2: 输入: 1 1 / \ 2 2 ...
分类:
其他好文 时间:
2019-08-18 23:38:22
阅读次数:
125
题目:验证一个二叉树是否为二叉排序树 注: 采用遍历二叉树的中序遍历,如果结果为排序,则说明该二叉树是二叉排序树 ...
分类:
其他好文 时间:
2019-08-18 17:49:52
阅读次数:
76
Bi Luo is a magic boy, he also has a migic tree, the tree has NN nodes , in each node , there is a treasure, it's value is V[i]V[i], and for each edge ...
分类:
其他好文 时间:
2019-08-18 14:00:56
阅读次数:
73
分析:比较容易想到的是用两个容器分别存放需要'1'变为'0'的值以及需要'0'变为'1'的值,1->0需要从大到小排序,0->1的需要从小到大排序进行贪心选择 但是如果存在这样的位置(变化前后都为1),我们就要枚举一开始把哪些这样的位置进行转换,显然是价值越大的越优先转换,因为这样代价小。 ...
分类:
其他好文 时间:
2019-08-18 12:10:11
阅读次数:
73
笛卡尔树模板题,但是蒟蒻调这道题比调它的变式题目调的更久,我果然是菜过头了 "原题传送门" include define ll long long using namespace std; const int maxn = 50000 + 10; int n, top; int fa[maxn], ...
分类:
其他好文 时间:
2019-08-18 12:00:41
阅读次数:
87
class BSTIterator { private Stack stack; public BSTIterator(TreeNode root) { stack = new Stack(); while(root != null){ stack.push(root); root = root..... ...
分类:
其他好文 时间:
2019-08-18 10:14:16
阅读次数:
90
Question Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in whic ...
分类:
其他好文 时间:
2019-08-18 09:59:24
阅读次数:
100
其实就是一个二分搜索 首先遍历LinkedList,记下链表长度 然后从mid开始, mid.left = 左部的mid mid.right = 右部的mid 依次递归,因为这相当于一个中序遍历,调用栈的最底层是从LinkedList首个元素开始的 ...
分类:
其他好文 时间:
2019-08-18 09:17:40
阅读次数:
74