dynamic programming
feeeeeeet
这个作者很懒,什么都没留下…
展开
-
Leetcode 5. Longest Palindromic Substring
3 solutions-Dynamic Programming & Expand Around Center &Solution 1 Dynamic ProgrammingThe process of compute dp[i][j] is showed as following:0000 011100 01 0211 122200 01 02 0311 12...原创 2018-11-12 04:01:51 · 102 阅读 · 0 评论 -
Leetcode 45&55. Jump Game I &II
There are many solutions for these two problems. For Jump Game I, greedy is the best method, but we can also use DP to solve it.Jump Game ISolution 1 DPThere are two kind of DP solution, bottom-up...原创 2018-12-13 01:02:27 · 161 阅读 · 0 评论 -
Leetcode 53. Maximum Subarray
max(sum,tmp+currentnum,currentnum)If currentnum+tmp>tmp and tmp<0(such as tmp=-2,currentnum=4), discard the elements before current element.class Solution(object): def maxSubArray(self, nu...原创 2018-12-12 05:32:00 · 88 阅读 · 0 评论 -
Leetcode 70. Climbing Stairs
recursion & dp(Fibonacci Number)Recursion!TLEclass Solution: def climbStairs(self, n): """ :type n: int :rtype: int """ if n == 1: retur...原创 2018-12-28 23:43:58 · 96 阅读 · 0 评论 -
Leetcode 62 & 63. Unique Paths I &II
key point: Unique Paths II fast versionUnique Paths Iclass Solution: def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ dp...原创 2018-12-26 01:22:34 · 100 阅读 · 0 评论 -
Leetcode 64. Minimum Path Sum
class Solution: def minPathSum(self, grid): """ :type grid: List[List[int]] :rtype: int """ m=len(grid) n=len(grid[0]) for i in range(m): ...原创 2018-12-26 01:36:48 · 81 阅读 · 0 评论