题意: 给出一颗树,有4种操作: 1、如果x和y不在同一棵树上则在xy连边 2、如果x和y在同一棵树上并且x!=y则把x换为树根并把y和y的父亲分离 3、如果x和y在同一棵树上则x到y的路径上所有的点权值+w 4、如果x和y在同一棵树上则输出x到y路径上的最大值动态树入门题:#includ...
分类:
其他好文 时间:
2014-10-04 22:37:27
阅读次数:
238
/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Soluti...
分类:
其他好文 时间:
2014-10-04 15:07:46
阅读次数:
162
Minimum Depth of Binary Tree
Total Accepted: 24760 Total
Submissions: 83665My Submissions
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the ...
分类:
其他好文 时间:
2014-10-04 12:50:06
阅读次数:
146
1156. Binary treeConstraintsTime Limit: 1 secs, Memory Limit: 32 MBDescriptionYour task is very simple: Given a binary tree, every node of which conta...
分类:
其他好文 时间:
2014-10-04 03:10:25
阅读次数:
202
Binary Tree PreOrder Traversal:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ ...
分类:
编程语言 时间:
2014-10-04 02:51:25
阅读次数:
285
和求最深二叉树相似,给定一个二叉树,求它的最小深度。最小深度是沿从根节点,到叶节点最短的路径。...
分类:
其他好文 时间:
2014-10-04 01:58:35
阅读次数:
154
给定一个二叉树,求它的最大深度。最大深度是沿从根节点,到叶节点最长的路径。...
分类:
其他好文 时间:
2014-10-04 01:10:05
阅读次数:
186
把三个二叉树遍历的题放在一起了。递归写法太简单,就不再实现了,每题实现了两种非递归算法。一种是利用栈,时间和空间复杂度都是O(n)。另一种是借助线索二叉树,也叫Morris遍历,充分利用树中节点的空指针域。先序:Binary Tree Preorder TraversalGiven a binary...
分类:
其他好文 时间:
2014-10-03 23:07:55
阅读次数:
341
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).
For example:
Given binary tree {3,9,20,#,#,15,7},
...
分类:
其他好文 时间:
2014-10-03 19:41:45
阅读次数:
189
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* Lis...
分类:
其他好文 时间:
2014-10-03 17:21:45
阅读次数:
167