DynamicProgramming
weixin_39145266
这个作者很懒,什么都没留下…
展开
-
198 House Robber
1 题目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...原创 2019-12-24 06:52:31 · 59 阅读 · 0 评论 -
1218 Longest Arithmetic Subsequence of Given Difference
1 题目Given an integer arrayarrand an integerdifference, return the length of the longest subsequence inarrwhich is an arithmetic sequence such that the difference between adjacent elements in th...原创 2019-12-24 06:21:58 · 106 阅读 · 0 评论 -
1223 Dice Roll Simulation
1 题目A die simulator generates a random number from 1 to 6 for each roll.You introduced a constraint to the generator such that it cannot roll the numberimore thanrollMax[i](1-indexed)consecuti...原创 2019-12-24 05:24:18 · 295 阅读 · 0 评论 -
1155 Number of Dice Rolls With Target Sum
1 题目You haveddice, and each die hasffaces numbered1, 2, ..., f.Return the number of possible ways (out offdtotal ways)modulo10^9 + 7to roll the dice so the sum of the face up numbers equ...原创 2019-12-18 10:47:23 · 151 阅读 · 0 评论 -
472 Concatenated Words
1 题目Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is comprised e...原创 2019-12-01 13:00:20 · 76 阅读 · 0 评论 -
1143 Longest Common Subsequence
1 题目Given two stringstext1andtext2, return the length of their longest common subsequence.Asubsequenceof a string is a new string generated from the original string with some characters(can b...原创 2019-11-26 13:54:20 · 91 阅读 · 0 评论 -
1025 Divisor Game
1 题目Alice and Bob take turns playing a game, with Alice starting first.Initially, there is a numberNon the chalkboard. On each player's turn, that player makes amoveconsisting of:Choosinga...原创 2019-08-03 12:00:38 · 122 阅读 · 0 评论 -
746 Min Cost Climbing Stairs
1 题目On a staircase, thei-th step has some non-negative costcost[i]assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the t...原创 2019-08-03 11:24:11 · 52 阅读 · 0 评论 -
70 Climbing Stairs
1 题目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 to the top?Note:Givennwill be a po...原创 2019-08-02 17:46:37 · 58 阅读 · 0 评论 -
413 Arithmetic Slices
1 题目A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic seq...原创 2019-07-12 15:29:58 · 119 阅读 · 0 评论 -
343 Integer Break
1 题目Given a positive integern, break it into the sum ofat leasttwo positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Out...原创 2019-07-07 15:15:09 · 56 阅读 · 0 评论 -
338 Counting Bits
1 题目Given a non negative integer numbernum. For every numbersiin the range0 ≤ i ≤ numcalculate the number of 1's in their binary representation and return them as an array.Example 1:Input: ...原创 2019-07-06 22:57:20 · 88 阅读 · 0 评论 -
309 Best Time to Buy and Sell Stock with Cooldown
1 题目Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, bu...原创 2019-06-30 16:32:28 · 96 阅读 · 0 评论 -
718 Maximum Length of Repeated Subarray
1 题目Given two integer arraysAandB, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated su...原创 2019-08-03 12:25:23 · 57 阅读 · 0 评论 -
712 Minimum ASCII Delete Sum for Two Strings
1 题目Given two stringss1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.Example 1:Input: s1 = "sea", s2 = "eat"Output: 231Explanation: Deleting "s" from "sea" ...原创 2019-08-03 13:48:59 · 49 阅读 · 0 评论 -
647 Palindromic Substrings
1 题目Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they co...原创 2019-08-03 17:26:39 · 47 阅读 · 0 评论 -
646 Maximum Length of Pair Chain
1 题目You are givennpairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair(c, d)can follow another pair(a, b)if and only ifb < c. ...原创 2019-08-03 19:51:42 · 62 阅读 · 0 评论 -
467 Unique Substrings in Wraparound String
1 题目Consider the stringsto be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", soswill look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....".Now we h...原创 2019-08-04 17:01:22 · 49 阅读 · 0 评论 -
486 Predict the Winner
1 题目Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on. Each time a player p...原创 2019-08-05 12:51:06 · 58 阅读 · 0 评论 -
474 Ones and Zeroes
1 题目In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator ofm0sandn1srespectively. On the ...原创 2019-08-05 20:26:08 · 63 阅读 · 0 评论 -
650 2 Keys Keyboard
1 题目Initially on a notepad only one character 'A' is present. You can perform two operations on this notepad for each step:Copy All: You can copy all the characters present on the notepad (partial...原创 2019-08-05 21:10:03 · 62 阅读 · 0 评论 -
516 Longest Palindromic Subsequence
1 题目Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest pal...原创 2019-07-28 21:47:23 · 43 阅读 · 0 评论 -
368 Largest Divisible Subset
1 题目Given a set ofdistinctpositive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies:Si% Sj= 0 or Sj% Si= 0.If there are multiple solutio...原创 2019-07-10 15:05:12 · 94 阅读 · 0 评论 -
376 Wiggle Subsequence
1 题目A sequence of numbers is called awiggle sequenceif the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be eith...原创 2019-07-10 12:19:18 · 227 阅读 · 0 评论 -
96. Unique Binary Search Trees
1 题目Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST's: 1 ...原创 2019-04-16 14:14:06 · 60 阅读 · 0 评论 -
152 Maximum Product Subarray
1 题目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: [...原创 2019-04-09 16:04:02 · 66 阅读 · 0 评论 -
213 House Robber II
1 题目You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first ho...原创 2019-04-11 23:11:58 · 82 阅读 · 0 评论 -
264 Ugly Number II
1 题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8,...原创 2019-04-11 21:47:42 · 68 阅读 · 0 评论 -
279 Perfect Squares
1 题目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: 3 Explanation: 12 = 4 + 4 + 4.E...原创 2019-04-08 15:47:35 · 87 阅读 · 0 评论 -
120 Triangle
1 题目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 following triangle[ [2], [3,4], ...原创 2019-04-08 14:26:44 · 124 阅读 · 0 评论 -
139 Word Break
1 题目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...原创 2019-04-11 20:02:15 · 141 阅读 · 0 评论 -
91 Decode Ways
1 题目A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given anon-emptystring containing only digits, deter...原创 2019-03-29 09:18:25 · 80 阅读 · 0 评论 -
64 Minimum Path Sum
1 题目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:You can only move either down or righ...原创 2019-03-29 09:18:18 · 50 阅读 · 0 评论 -
63 Unique Paths II
1 题目A robot is located at the top-left corner of amxngrid (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 ...原创 2019-03-29 09:16:42 · 59 阅读 · 0 评论 -
95 Unique Binary Search Trees II
1 題目Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n.Example:Input: 3Output:[ [1,null,3,2], [3,2,null,1], [3,1,null,null,2], ...原创 2019-04-17 10:51:05 · 62 阅读 · 0 评论 -
53 Maximum Subarray
1 题目Given an integer arraynums, 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: 6Exp...原创 2019-04-26 10:01:06 · 64 阅读 · 0 评论 -
416 Partition Equal Subset Sum
1 题目Given anon-emptyarray containingonly positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array...原创 2019-07-14 12:08:11 · 68 阅读 · 0 评论 -
392 Is Subsequence
Given a stringsand a stringt, check ifsis subsequence oft.You may assume that there is only lower case English letters in bothsandt.tis potentially a very long (length ~= 500,000) string,...原创 2019-07-09 21:50:24 · 57 阅读 · 0 评论 -
377 Combination Sum IV
1 题目Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4Th...原创 2019-07-08 14:41:56 · 67 阅读 · 0 评论 -
357 Count Numbers with Unique Digits
1 题目Given anon-negativeinteger n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example:Input: 2Output: 91 Explanation: The answer should be the total numbers in the range o...原创 2019-07-07 21:07:04 · 58 阅读 · 0 评论