DescriptionThe inversion number of a given
number sequence a1, a2, ..., an is the number of pairs (ai, aj) that satisfy i
aj.For a given sequence of ....
分类:
其他好文 时间:
2014-05-05 11:42:13
阅读次数:
276
判断树是否是平衡的,这道题中的平衡的概念是指任意节点的两个子树的高度相差不超过1,我用递归的方法把所有的节点的高度都计算了下,并且在计算的过程记录每个节点左右两颗子树的高度差,最后通过遍历这个高度差就可以知道是否是平衡的。下面是AC代码:
1 /** 2 * Given a binary...
分类:
其他好文 时间:
2014-05-05 09:54:44
阅读次数:
378
这两道题,大同小异。
我都是用BFS,在遍历的过程,判断结构是否相同/对称,值是否相同。下面是AC代码: 1 /** 2 * Given a binary tree, check
whether it is a mirror of itself (ie, symmetric aroun...
分类:
其他好文 时间:
2014-05-05 09:48:26
阅读次数:
401
BFS以及它的扩展,我发现栈是个很好用的数据结构,特别是对于顺序需要颠倒的时候!!!这里有个重要的信息:可以用null来标识一个level的结束!!!下面是AC代码:
1 /** 2 * Given a binary tree, return the bottom-up level ord...
分类:
其他好文 时间:
2014-05-05 09:46:06
阅读次数:
402
题目:Given an array of strings, return all groups of
strings that are anagrams.Note: All inputs will be in lower-case.class Solution
{public: vector ...
分类:
其他好文 时间:
2014-05-04 20:48:08
阅读次数:
608
Given a non-negative number represented as an array
of digits, plus one to the number.The digits are stored such that the most
significant digit is at...
分类:
其他好文 时间:
2014-05-04 19:46:18
阅读次数:
372
Minimum Inversion Number Time Limit:1000MS Memory
Limit:32768KB 64bit IO Format:%I64d & %I64u Description The inversion number
of a given number seque...
分类:
其他好文 时间:
2014-05-04 12:27:07
阅读次数:
349
Suppose there are 5 types of coins: 50-cent,
25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins
for a given amount of mone...
分类:
其他好文 时间:
2014-05-04 12:00:00
阅读次数:
363
题目描述:1038. Recover the Smallest Number
(30)Given a collection of number segments, you are supposed to recover the
smallest number from them. For examp...
分类:
其他好文 时间:
2014-05-04 10:49:34
阅读次数:
308
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an...
分类:
其他好文 时间:
2014-05-03 21:35:49
阅读次数:
310