"trie的经典应用" -- by hzwer我们把每个点到根的xor值记下来,然后找出两个xor值最大的即可(因为(a ^ c) ^ (b ^ c) = a ^ b)于是用trie把每个数的二进制位记下来,每次query的时候利用贪心,试图走到另一个儿子即可。 1 /**************....
分类:
其他好文 时间:
2014-12-20 23:28:26
阅读次数:
362
Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4...
分类:
其他好文 时间:
2014-12-20 16:49:31
阅读次数:
178
题目
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
解答
求二叉树的最大深度。
递归:a.若二叉树为空,...
分类:
其他好文 时间:
2014-12-20 15:38:37
阅读次数:
173
One TopCoder article introduces a very interesting alternative solution to Longest Common Sequences problem.It is based on this statement (http://comm...
分类:
其他好文 时间:
2014-12-20 10:26:37
阅读次数:
240
Write a function to find the longest common prefix string amongst an array of strings.
方法一,单个字符横向全体比较,纵向逐个的收集。
class Solution {
public:
string longestCommonPrefix(vector &strs) {
i...
分类:
其他好文 时间:
2014-12-19 15:48:20
阅读次数:
142
题解:在树上i到j的异或和可以直接转化为i到根的异或和^j到根的异或和。所以我们把每个点到根的异或和处理出来放到trie里面,再把每个点放进去跑一遍即可。代码: 1 #include 2 3 #include 4 5 #include 6 7 #include 8 9 #i...
分类:
其他好文 时间:
2014-12-19 14:11:36
阅读次数:
266
题目Maximum Depth of Binary Tree通过率44.2%难度EasyGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest pat...
分类:
其他好文 时间:
2014-12-18 20:28:05
阅读次数:
214
标题:Maximum Depth of Binary Tree通过率:44.2%难度:简单Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest pa...
分类:
其他好文 时间:
2014-12-18 15:05:18
阅读次数:
153
Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substr...
分类:
其他好文 时间:
2014-12-18 11:48:19
阅读次数:
158
题目1042:Coincidence
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:1689
解决:898
题目描述:
Find a longest common subsequence of two strings.
输入:
First and second line of each input case co...
分类:
其他好文 时间:
2014-12-18 01:42:32
阅读次数:
162