dynamic programming
Vendredimatin
这个作者很懒,什么都没留下…
展开
-
Leetcode dynamic programming Top interview Question 15道题总结
本文是对leetcode中dynamic programing标签下的top interview question进行总结leetcode 62. Unique Pathsdp[i][j] = dp[i-1][j] + dp[i][j-1]dp[i][j]代表走到(i,j)坐标的所有路径数Leetcode 121. Best Time to Buy and Sell Stockdp[i] = min(dp[i-1], nums[i])dp[i]代表i之前的最小价格数,记录的并不是直接结果,而是序原创 2020-07-06 11:22:30 · 184 阅读 · 0 评论 -
Leetcode 91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, determine the total number of ways to decode it.Example 1:Input: “12”O原创 2020-07-05 22:39:58 · 142 阅读 · 0 评论 -
Leetcode 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example 2:Input: “cbbd”Output: “bb”method dp字符串回文dp,思维方式在Lee原创 2020-07-05 22:34:41 · 224 阅读 · 0 评论 -
Leetcode 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, retur原创 2020-07-05 22:27:29 · 113 阅读 · 0 评论 -
Leetcode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences.Note:The same word in the dictionary may be原创 2020-07-05 22:08:29 · 105 阅读 · 0 评论 -
Leetcode 198. House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatical原创 2020-07-05 13:31:21 · 116 阅读 · 0 评论 -
Leetcode 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Example 1:Input: 2Output: 2Explanation: There are two ways to climb to the top.1 step原创 2020-07-05 10:53:15 · 209 阅读 · 0 评论 -
Leetcode 121. Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.Note tha原创 2020-07-05 10:40:27 · 109 阅读 · 0 评论 -
Leetcode 139. Word Break
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The same word in the dictionary may be reused multiple times i原创 2020-06-29 19:38:05 · 115 阅读 · 0 评论 -
Leetcode 300.longest-increasing-subsequence
method 1 dp使用动态规划,dp[i]代表以第i个数结尾时的最大长度//dp[i]表示以num[i]结尾的序列的最大长度int lengthOfLIS(vector<int>& nums) { if (nums.size() == 0) return 0; vector<int> dp(nums.size(), 1); for (int i = 1; i < nums.size(); i++) { for (int j = 0; j <原创 2020-06-29 11:47:41 · 126 阅读 · 0 评论 -
Leetcode 140. Word Break II
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible ...原创 2020-02-14 11:17:40 · 115 阅读 · 0 评论 -
Leetcode 131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]...原创 2020-02-14 11:06:02 · 100 阅读 · 0 评论 -
Leetcode 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.Example 1:Input: n = 12Output: 3Explanation: 12 = 4 + 4 + 4.Example 2:Inp...原创 2020-02-09 20:16:50 · 140 阅读 · 0 评论 -
leetcode 152. Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [2,3] has ...原创 2019-06-22 15:37:36 · 154 阅读 · 0 评论 -
Leetcode 55. Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you ...原创 2019-06-22 15:33:39 · 210 阅读 · 0 评论 -
leetcode 62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bot...原创 2019-06-09 17:13:27 · 133 阅读 · 0 评论 -
leetcode 53. Maximum Subarray
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2019-05-20 12:15:50 · 107 阅读 · 0 评论