Problem Description:Sort a linked list inO(nlogn) time using constant space complexity.Solution: 1 public ListNode sortList(ListNode head) { 2 ...
分类:
其他好文 时间:
2014-07-07 16:48:00
阅读次数:
238
Problem Description:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Solution: 1 public bo....
分类:
其他好文 时间:
2014-07-07 16:08:01
阅读次数:
151
Problem Description:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more diction...
分类:
其他好文 时间:
2014-07-07 16:02:11
阅读次数:
219
Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe...
分类:
其他好文 时间:
2014-07-07 15:30:23
阅读次数:
169
原题: URAL 1091 http://acm.timus.ru/problem.aspx?space=1&num=1091题意:要求找出K个不同的数字使他们有一个大于1的公约数,且所有的数字都不能大于一个指定的数字S。解法:可以考虑每个S内的素数,此素数和它的所有倍数构成一个集合,则可以在这些集...
分类:
其他好文 时间:
2014-07-02 00:37:32
阅读次数:
253
Weekly golfers will find a bag that gives them enough space to do a lot of tees, balls, sticks, and whatever he deems necessary for the golf course. P...
分类:
其他好文 时间:
2014-06-30 20:52:39
阅读次数:
258
【题目】
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
For example, given
s = "leetcode",
dict = ["leet", "code"].
Return true because "leetcode" can be segm...
分类:
其他好文 时间:
2014-06-30 09:02:26
阅读次数:
276
题目
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
Follow up:
Did you use extra space?
A straight forward solution using O(mn) space is probab...
分类:
其他好文 时间:
2014-06-30 06:17:09
阅读次数:
245
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1143
题意:逆时针给一个凸包的n(n
解法:求最短哈密顿本身是一个NP问题,但是因为是凸包上,可以利用这个做;有一个性质:凸包上的最短哈密顿路径不会出现交叉。所以可以看出来从一点出发,他要么和顺时针相邻点连接,要么和逆时针相邻点相连接;通过这个性质可以通过dp做:
ans[i][j...
分类:
其他好文 时间:
2014-06-30 06:11:07
阅读次数:
328
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1147
题意:一个10000*10000的矩阵,初始颜色都为1,然后最多2500次涂色,每次涂色将一个矩形的面积涂成某个特定颜色,问涂完之后每种颜色最终的面积。
解法:
代码:/*********************************************...