摘要: 网上看到的转过来一下,顺便把题目都加了个超链接,方便刷起~POJ上的一些水题(可用来练手和增加自信)(poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期:一.基本算法: (1)枚举. (poj1753,... 阅读全文
posted @ 2014-08-01 00:16 flowerkzj 阅读(266) 评论(0) 推荐(0) 编辑
摘要: Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the be... 阅读全文
posted @ 2014-06-10 01:10 flowerkzj 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Word LadderGiven two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one let... 阅读全文
posted @ 2014-05-16 19:54 flowerkzj 阅读(335) 评论(0) 推荐(0) 编辑
摘要: Wildcard MatchingImplement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters... 阅读全文
posted @ 2014-05-15 13:18 flowerkzj 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Regular Expression MatchingImplement regular expression matching with support for'.'and'*'.'.' Matches any single character.'*' Matches zero or more o... 阅读全文
posted @ 2014-05-14 00:14 flowerkzj 阅读(1671) 评论(0) 推荐(1) 编辑
摘要: Recover Binary Search TreeTwo elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A sol... 阅读全文
posted @ 2014-04-07 16:20 flowerkzj 阅读(149) 评论(0) 推荐(0) 编辑
摘要: SubsetsGiven a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]罗列所有的子集,要求每一个子集的元素有序,且... 阅读全文
posted @ 2014-04-06 02:07 flowerkzj 阅读(465) 评论(0) 推荐(0) 编辑
摘要: 实现Pow(x, n)累乘当然可以,但效率太低了。网上搜的很多用的都是分治的思想,递归实现,感觉有点复杂。分析下吧n = n1 * 2^0 + n2 * 2^1 + n3 * 2^2 + ...x^n = x^(n1 * 2^0 + n2 * 2^1 + n3 * 2^2 + ...) = (x^(2^0))^n0 *(x^(2^1))^n1 * ...也许这么看着很复杂,其实就是把n分解成二进制数就很清晰了,为1的位才相乘,为0的跳过,另外还要处理次幂为负的情况,看了代码就清晰~ 1 class Solution { 2 public: 3 double pow(double x, ... 阅读全文
posted @ 2014-04-06 00:18 flowerkzj 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Populating Next Right Pointers in Each NodeGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.In... 阅读全文
posted @ 2014-04-04 11:38 flowerkzj 阅读(161) 评论(0) 推荐(0) 编辑
摘要: Sort ColorsGiven an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose t 阅读全文
posted @ 2014-04-04 11:24 flowerkzj 阅读(177) 评论(0) 推荐(0) 编辑