dynamic programming
Goofiness
这个作者很懒,什么都没留下…
展开
-
[LeetCode]Maximum Subarray Sum with One Deletion@Golang
Maximum Subarray Sum with One DeletionGiven an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to ...原创 2019-11-12 22:48:28 · 398 阅读 · 0 评论 -
[LeetCode]Number of Dice Rolls With Target Sum@Golang
Number of Dice Rolls With Target SumYou have d dice, and each die has f faces numbered 1, 2, …, f.Return the number of possible ways (out of fd total ways) modulo 10^9 + 7 to roll the dice so the su...原创 2019-11-12 22:12:21 · 282 阅读 · 0 评论 -
[LeetCode]Longest Common Subsequence@Golang
Longest Common SubsequenceGiven two strings text1 and text2, return the length of their longest common subsequence.A subsequence of a string is a new string generated from the original string with s...原创 2019-11-08 09:06:36 · 274 阅读 · 0 评论 -
[LeetCode]Stone Game II@Golang
Stone Game IIAlex and Lee continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of stones piles[i]. The objective of ...原创 2019-11-06 22:24:05 · 178 阅读 · 0 评论 -
[LeetCode]Largest 1-Bordered Square@Golang
Largest 1-Bordered SquareGiven a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has all 1s on its border, or 0 if such a subgrid doesn’t exist in the grid.Exa...原创 2019-11-06 16:14:20 · 113 阅读 · 0 评论 -
[LeetCode]Filling Bookcase Shelves@Golang
Filling Bookcase ShelvesWe have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1].We want to place these books in order onto bookcase shelves that have total width ...原创 2019-11-02 00:06:40 · 163 阅读 · 0 评论 -
[LeetCode]Minimum Cost For Tickets@Golang
Minimum Cost For TicketsIn a country popular for train travel, you have planned some train travelling one year in advance. The days of the year that you will travel is given as an array days. Each ...原创 2019-10-21 11:26:03 · 133 阅读 · 0 评论 -
[LeetCode]Longest Turbulent Subarray@Golang
Longest Turbulent SubarrayA subarray A[i], A[i+1], …, A[j] of A is said to be turbulent if and only if:For i <= k < j, A[k] > A[k+1] when k is odd, and A[k] < A[k+1] when k is even;OR, ...原创 2019-10-17 15:33:33 · 122 阅读 · 0 评论 -
[LeetCode]Minimum Falling Path Sum@Golang
Minimum Falling Path SumGiven a square array of integers A, we want the minimum sum of a falling path through A.A falling path starts at any element in the first row, and chooses one element from ea...原创 2019-10-15 11:21:41 · 83 阅读 · 0 评论 -
[LeetCode]Bitwise ORs of Subarrays@Golang
Bitwise ORs of SubarraysWe have an array A of non-negative integers.For every (contiguous) subarray B = [A[i], A[i+1], …, A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obt...原创 2019-10-14 11:27:47 · 101 阅读 · 0 评论 -
[LeetCode]Unique Substrings in Wraparound String@Python
Unique Substrings in Wraparound StringConsider the string s to be the infinite wraparound string of “abcdefghijklmnopqrstuvwxyz”, so s will look like this: “…zabcdefghijklmnopqrstuvwxyzabcdefghijklmn...原创 2019-07-26 16:28:12 · 117 阅读 · 0 评论 -
[Leetcode]Maximum Length of Pair Chain@Python
Maximum Length of Pair ChainYou are given n pairs 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...原创 2019-09-05 16:39:39 · 98 阅读 · 0 评论 -
[LeetCode]Palindromic Substrings@Python
Palindromic SubstringsGiven 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 substr...原创 2019-09-06 15:16:23 · 103 阅读 · 0 评论 -
[LeetCode]Number of Longest Increasing Subsequence@Python
Number of Longest Increasing SubsequenceGiven an unsorted array of integers, find the number of longest increasing subsequence.ExampleInput: [1,3,5,4,7]Output: 2Explanation: The two longest in...原创 2019-09-12 11:38:06 · 66 阅读 · 0 评论 -
[LeetCode]Minimum ASCII Delete Sum for Two Strings@Python
Minimum ASCII Delete Sum for Two StringsGiven two strings s1, s2, find the lowest ASCII sum of deleted characters to make two strings equal.ExampleInput: s1 = “sea”, s2 = “eat”Output: 231Explana...原创 2019-09-18 15:55:19 · 102 阅读 · 0 评论 -
[LeetCode]Maximum Length of Repeated Subarray@Python
Maximum Length of Repeated SubarrayGiven two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.ExampleInput:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Expl...原创 2019-09-19 13:42:19 · 73 阅读 · 0 评论 -
[LeetCode]Min Cost Climbing Stairs@Python
Min Cost Climbing StairsOn a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum c...原创 2019-09-19 14:08:48 · 183 阅读 · 0 评论 -
[LeetCode]Minimum Swaps To Make Sequences Increasing@Python
Minimum Swaps To Make Sequences IncreasingWe have two integer sequences A and B of the same non-zero length.We are allowed to swap elements A[i] and B[i]. Note that both elements are in the same in...原创 2019-09-25 15:15:31 · 116 阅读 · 0 评论 -
[LeetCode]Largest Sum of Averages@Python
Largest Sum of AveragesWe partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the sum of the average of each group. What is the largest score we can achieve?No...原创 2019-09-26 15:45:17 · 154 阅读 · 0 评论 -
[LeetCode]Length of Longest Fibonacci Subsequence@Golang
Length of Longest Fibonacci SubsequenceA sequence X_1, X_2, …, X_n is fibonacci-like if:n >= 3X_i + X_{i+1} = X_{i+2} for all i + 2 <= nGiven a strictly increasing array A of positive intege...原创 2019-10-10 11:09:42 · 101 阅读 · 0 评论 -
[LeetCode]Unique Binary Search Trees@Python
Unique Binary Search TreesGiven n, how many structurally unique BST’s (binary search trees) that store values 1 … n?ExampleInput: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique...原创 2019-07-10 17:02:03 · 85 阅读 · 0 评论 -
[LeetCode]Longest Palindromic Subsequence@Python
Longest Palindromic SubsequenceGiven a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.ExampleInput:“cbbd”Output:2One possi...原创 2019-07-31 11:00:17 · 161 阅读 · 0 评论 -
[LeetCode]Combination Sum IV@Python
Combination Sum IVGiven an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Examplenums = [1, 2, 3]targe...原创 2019-07-22 10:33:53 · 100 阅读 · 0 评论 -
[LeetCode]Unique Paths@Python
Unique PathsA 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 ...原创 2019-07-06 01:14:07 · 99 阅读 · 0 评论 -
[LeetCode]Perfect Squares@Python
Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.ExampleInput: n = 12Output: 3Explanation: 12 = 4 + 4 + 4.S...原创 2019-07-15 17:33:51 · 193 阅读 · 0 评论 -
[LeetCode]Triangle@Python
TriangleGiven 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 triangleExample[[2],[3,4],[6,5,...原创 2019-07-11 11:36:27 · 149 阅读 · 0 评论 -
[LeetCode]Unique Binary Search Trees II@Python
Unique Binary Search Trees IIGiven an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.ExampleInput: 3Output:[[1,null,3,2],[3,2,null,1],[3,1,null...原创 2019-07-11 10:42:00 · 77 阅读 · 0 评论 -
[LeetCode]Word Break@Python
Word BreakGiven 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.N...原创 2019-07-12 17:23:41 · 309 阅读 · 0 评论 -
[LeetCode]limbing Stairs@Python
limbing StairsYou 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?Note: Given n will ...原创 2019-07-08 23:49:19 · 70 阅读 · 0 评论 -
[LeetCode]Longest Palindromic Substring@Python
Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.ExampleInput: “babad”Output: “bab”Note: “aba” is al...原创 2019-07-01 22:53:34 · 94 阅读 · 0 评论 -
[LeetCode]Cheapest Flights Within K Stops@Python
Cheapest Flights Within K StopsThere are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and flights, together with starting ...原创 2019-05-19 21:11:28 · 133 阅读 · 0 评论 -
[LeetCode]Unique Paths II@Python
Unique Paths IIA 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 ...原创 2019-07-06 11:47:23 · 134 阅读 · 0 评论 -
[LeetCode]Minimum Path Sum@Python
Minimum Path SumGiven a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either do...原创 2019-07-06 12:34:55 · 99 阅读 · 0 评论 -
[LeetCode]Integer Break@Python
Integer BreakGiven a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.ExampleInput: 10...原创 2019-07-18 10:07:32 · 96 阅读 · 0 评论 -
[LeetCode]Target Sum@Python
Target SumYou are given a list of non-negative integers, a1, a2, …, an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.Find o...原创 2019-07-30 20:58:04 · 194 阅读 · 0 评论 -
[LeetCode]Can I Win@Python
Can I WinIn the “100 game,” two players take turns adding, to a running total, any integer from 1…10. The player who first causes the running total to reach or exceed 100 wins.What if we change the ...原创 2019-07-25 15:30:16 · 121 阅读 · 0 评论 -
[LeetCode]Partition Equal Subset Sum@Python
Partition Equal Subset SumGiven a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note...原创 2019-07-24 10:51:52 · 116 阅读 · 0 评论 -
[LeetCode]Largest Divisible Subset@Python
Largest Divisible SubsetGiven a set of distinct positive 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...原创 2019-07-19 16:09:46 · 134 阅读 · 0 评论 -
[LeetCode]Predict the Winner@Python
Predict the WinnerGiven 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 ti...原创 2019-07-29 10:07:54 · 159 阅读 · 0 评论 -
[LeetCode]Coin Change@Python
Coin ChangeYou 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 amou...原创 2019-07-17 10:29:59 · 141 阅读 · 0 评论