2014年4月6日

摘要: Problem link:http://oj.leetcode.com/problems/candy/Suppose we are given an array R[1..N] that are ratings of N children.Let C[1..N] be a new array where C[i] is the number of candies for i-th child.From the description, C[i] should meet following requirements:LEAST. C[i] is at least 1, for i = 1, .. 阅读全文

posted @ 2014-04-06 23:30 卢泽尔 阅读(288) 评论(0) 推荐(0)

摘要: Problem link:http://oj.leetcode.com/problems/copy-list-with-random-pointer/Deepcopy a linked list with random pointer, realy simple problem, solved in three steps using a hash map:Create a new head, duplicating the head (return NULL for case head==NULL), map key=p1 with value=p2.Let p1 point to head 阅读全文

posted @ 2014-04-06 12:03 卢泽尔 阅读(205) 评论(0) 推荐(0)

摘要: Problem link:http://oj.leetcode.com/problems/word-break-ii/This problem is some extension of the word break problem, so the solution is based on the discussion in Word Break.We also use DP to solve the problem. In this solution, A[i] is not a boolean any more, but a list of all possible value of j&g 阅读全文

posted @ 2014-04-06 11:30 卢泽尔 阅读(587) 评论(0) 推荐(0)

摘要: Problem link:http://oj.leetcode.com/problems/word-break/We solve this problem using Dynamic Programming method. Let A[0..n-1] be a boolean array, where A[i]=True if and only if s[i..n-1] can be segmented into words. The recursive formula is:A[i] = True, if s[i..n-1] is a wordA[i] = True, if there ex 阅读全文

posted @ 2014-04-06 10:46 卢泽尔 阅读(654) 评论(0) 推荐(0)