摘要: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ ... 阅读全文
posted @ 2013-12-04 22:02 七年之后 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if you are a... 阅读全文
posted @ 2013-12-04 21:28 七年之后 阅读(214) 评论(0) 推荐(0) 编辑
摘要: Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should preserve the original relative order of the nodes in each of the two partitions.For example,Given1->4->3->2->5->2andx= 3,return1->2->2->4->3- 阅读全文
posted @ 2013-12-04 20:37 七年之后 阅读(209) 评论(0) 推荐(0) 编辑
摘要: “选择了错误的算法,便注定了失败的命运”。最近对这句话感触颇深,经常因为一开始思路错误,修改半天,到头来却都是无用功,所以学好算法势在必行。算法的泛化过程如何设计一个算法,使他适用于任何(大多数)数据结构呢?先看一个算法泛华的实例。假设我们要写一个find()函数,在array中寻找特定值。面对整数array,我们很快能写出:int *find(int *array,int size,int target){ for(int i=0;iT *find(T *begin,T *end,T& value){ while(begin!=end&&*begin!=value) 阅读全文
posted @ 2013-12-04 17:18 七年之后 阅读(532) 评论(0) 推荐(0) 编辑
摘要: The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off as"one 2, thenone 1"or1211.Given an integern, generate thenthsequence.Note: The sequence of inte 阅读全文
posted @ 2013-12-04 00:37 七年之后 阅读(244) 评论(0) 推荐(0) 编辑