
DP
文章平均质量分 62
myangel_xy
这个作者很懒,什么都没留下…
展开
-
【LeetCode】72. Edit Distance单词变换的最少操作
问题描述Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a原创 2017-06-18 20:50:05 · 550 阅读 · 0 评论 -
【LeetCode】152. Maximum Product Subarray最大连续子数组乘积
问题描述Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4], the contiguous subarray [2,3] has the largest p原创 2017-06-23 19:58:50 · 255 阅读 · 0 评论 -
【LeetCode】312. Burst Balloons爆破气球得到最大金币数
问题描述给定n个气球,每个气球对应一个编号,用数组nums[0…n-1]存放,打爆一个气球能够获得金币数:nums[left] * nums[i] * nums[right],然后这个数被移除,left和right变为相邻。求能够获得的最多的金币数量。 注:①假设nums[-1] = nums[n] = 1 ② 0 ≤ n ≤ 500, 0 ≤ nums[i] ≤ 100例:Given [3,原创 2017-06-22 14:49:38 · 517 阅读 · 0 评论 -
【LeetCode】516. Longest Palindromic Subsequence最长回文子序列(非连续)
Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000. Input: “bbbab” Output: 4 一种可能的最长子序列为”bbbb”.原创 2017-05-11 22:04:53 · 496 阅读 · 0 评论 -
【LeetCode】300.Longest Increasing Subsequence最长递增子序列LIS
给定数组 [10, 9, 2, 5, 3, 7, 101, 18],其中一个最长递增子序列(不需要连续)为[2, 3, 7, 101] ,length为4。因为最长子序列不一定唯一,所以我们只需要返回长度值。 【解题思路】 老师上课讲的经典的一道动态规划。而且有两种方法:O(n2)和O(nlogn)。 (1)方法1:常规思路,O(n2) f[i]:表示以元素a[i]为结尾的最长递增子序列的原创 2017-04-26 01:11:02 · 267 阅读 · 0 评论 -
【LeetCode】53.Maximum Subarray最大连续子序列和
给定数组 [-2,1,-3,4,-1,2,1,-5,4],子序列[4,-1,2,1] 有最大和6。 【解题思路】 老师上课讲的经典的一道动态规划。 f[i]:表示以元素ai为结尾的子序列的最大和。 当i=0,f[i]=ai 当i>0, 如果f[i-1] 如果f[i-1]>=0,f[i]=f[i-1]+ai 答案:max{f[0],f[1],....,f[n]}。 T(n)=O原创 2017-04-23 02:17:04 · 393 阅读 · 0 评论 -
【LeetCode】No.53 Maximum Subarray
【原题】 Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1原创 2017-03-13 22:07:06 · 339 阅读 · 0 评论