随笔分类 -  DP

Dynamic Programming
摘要:Given a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is formed from the orig... 阅读全文
posted @ 2015-04-10 14:26 穆穆兔兔 阅读(183) 评论(0) 推荐(0) 编辑
摘要:Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="... 阅读全文
posted @ 2015-04-02 17:15 穆穆兔兔 阅读(233) 评论(0) 推荐(0) 编辑
摘要:Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni... 阅读全文
posted @ 2015-04-02 16:44 穆穆兔兔 阅读(182) 评论(0) 推荐(0) 编辑
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1... 阅读全文
posted @ 2015-04-02 16:02 穆穆兔兔 阅读(157) 评论(0) 推荐(0) 编辑
摘要:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message conta... 阅读全文
posted @ 2015-03-30 17:52 穆穆兔兔 阅读(183) 评论(0) 推荐(0) 编辑
摘要:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.... 阅读全文
posted @ 2015-03-30 17:02 穆穆兔兔 阅读(182) 评论(0) 推荐(0) 编辑
摘要:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation... 阅读全文
posted @ 2015-03-24 14:55 穆穆兔兔 阅读(278) 评论(0) 推荐(0) 编辑
摘要:You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb... 阅读全文
posted @ 2015-03-10 14:07 穆穆兔兔 阅读(135) 评论(0) 推荐(0) 编辑
摘要:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:Yo... 阅读全文
posted @ 2015-03-07 15:06 穆穆兔兔 阅读(201) 评论(0) 推荐(0) 编辑
摘要:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space i... 阅读全文
posted @ 2015-03-07 13:45 穆穆兔兔 阅读(140) 评论(0) 推荐(0) 编辑
摘要:Unique PathsTotal Accepted:36748Total Submissions:112531My SubmissionsQuestionSolutionA robot is located at the top-left corner of amxngrid (marked 'S... 阅读全文
posted @ 2015-03-07 13:12 穆穆兔兔 阅读(211) 评论(0) 推荐(0) 编辑
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs... 阅读全文
posted @ 2014-07-18 14:57 穆穆兔兔 阅读(151) 评论(0) 推荐(0) 编辑
摘要:Given a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, giv... 阅读全文
posted @ 2014-07-18 11:09 穆穆兔兔 阅读(242) 评论(0) 推荐(0) 编辑
摘要:分析转载 http://blog.csdn.net/joylnwang/article/details/6859677Find the contiguous subarray within an array (containing at least one number) which has the... 阅读全文
posted @ 2014-07-17 14:59 穆穆兔兔 阅读(197) 评论(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 fol... 阅读全文
posted @ 2014-07-17 11:42 穆穆兔兔 阅读(150) 评论(0) 推荐(0) 编辑
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl... 阅读全文
posted @ 2014-07-07 17:02 穆穆兔兔 阅读(227) 评论(0) 推荐(0) 编辑
摘要:Given two wordsword1andword2, find the minimum number of steps required to convertword1toword2. (each operation is counted as 1 step.)You have the fol... 阅读全文
posted @ 2014-07-04 17:56 穆穆兔兔 阅读(219) 评论(0) 推荐(0) 编辑
摘要:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:动态规划:f[i][j] 表示在第i行中以(i,j)点结束点... 阅读全文
posted @ 2014-07-04 10:36 穆穆兔兔 阅读(214) 评论(0) 推荐(0) 编辑
摘要:将Best Time to Buy and Sell Stock的如下思路用到此题目思路1:第i天买入,能赚到的最大利润是多少呢?就是i + 1 ~ n天中最大的股价减去第i天的。思路2:第i天买出,能赚到的最大利润是多少呢?就是第i天的价格减去0~ i-1天中最小的。和前两道题比起来的话,这道题最... 阅读全文
posted @ 2014-07-03 15:43 穆穆兔兔 阅读(232) 评论(0) 推荐(0) 编辑
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (ie... 阅读全文
posted @ 2014-07-03 11:23 穆穆兔兔 阅读(203) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示