动态规划
涛涛酱
北邮研究僧在读
展开
-
【LeetCode 1371】 Find the Longest Substring Containing Vowels in Even Counts
题目描述Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, ‘a’, ‘e’, ‘i’, ‘o’, and ‘u’ must appear an even number of times.Example 1:Input: s = "eleetminicoworoep"Output: 13Explanation: The原创 2020-06-15 00:16:52 · 251 阅读 · 0 评论 -
【LeetCode 887】 Super Egg Drop
题目描述You are given K eggs, and you have access to a building with N floors from 1 to N.Each egg is identical in function, and if an egg breaks, you cannot drop it again.You know that there exists a floor F with 0 <= F <= N such that any egg dropped原创 2020-06-01 19:01:50 · 100 阅读 · 0 评论 -
【LeetCode 300】 Longest Increasing Subsequence Medium
题目描述Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. Note:There may be mo原创 2020-05-31 00:58:54 · 109 阅读 · 0 评论 -
【LeetCode 983】 Minimum Cost For Tickets
题目描述In 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 day is an integer from 1 to 365.Train tickets are sold in 3 different ways:原创 2020-05-30 01:15:15 · 117 阅读 · 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 the largest product 6.Example 2:Input: [-2,0,-1]原创 2020-05-29 18:27:52 · 104 阅读 · 0 评论 -
【LeetCode 376】Wiggle Subsequence
题目描述A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with fewer than two e原创 2020-05-18 16:19:51 · 82 阅读 · 0 评论 -
【面试题 & LeetCode 486】Predict the Winner
题目描述一个整数数组,两个人一次分别从左边或者右边拿走一个数,两个人足够聪明,求第一个人拿到数的最大和。动态规划dp[i][j]表示该区间先手能取到的最大和。从小区间到大区间更新。代码class Solution {public: bool PredictTheWinner(vector<int>& nums) { int n = nums....原创 2020-04-23 23:37:26 · 199 阅读 · 0 评论 -
【面试题 & LeetCode 44】Wildcard Matching
题目描述Given an input string (s) and a pattern §, implement wildcard pattern matching with support for ‘?’ and ‘*’.‘?’ Matches any single character.‘*’ Matches any sequence of characters (including th...原创 2020-04-20 22:53:32 · 114 阅读 · 0 评论 -
【面试题 & LeetCode 221】Maximal Square
题目描述Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.Example:Input: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4思路dp[i][j...原创 2020-04-20 18:44:42 · 152 阅读 · 0 评论 -
【LeetCode 1220】 Count Vowels Permutation
题目描述Given an integer n, your task is to count how many strings of length n can be formed under the following rules:Each character is a lower case vowel (‘a’, ‘e’, ‘i’, ‘o’, ‘u’)Each vowel ‘a’ may o...原创 2020-03-09 23:28:22 · 302 阅读 · 0 评论 -
【LeetCode 1223】 Dice Roll Simulation
题目描述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 number i more than rollMax[i] (1-indexed) consecutiv...原创 2020-03-09 21:55:03 · 171 阅读 · 0 评论 -
【LeetCode 1218】 Longest Arithmetic Subsequence of Given Difference
题目描述Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the...原创 2020-03-08 21:42:19 · 164 阅读 · 0 评论 -
【Leetcode 1191】 K-Concatenation Maximum Sum
题目描述Given an integer array arr and an integer k, modify the array by repeating it k times.For example, if arr = [1, 2] and k = 3 then the modified array will be [1, 2, 1, 2, 1, 2].Return the maximu...原创 2020-03-08 19:58:50 · 172 阅读 · 0 评论 -
【LeetCode 1187】 Make Array Strictly Increasing
题目描述Given two integer arrays arr1 and arr2, return the minimum number of operations (possibly zero) needed to make arr1 strictly increasing.In one operation, you can choose two indices 0 <= i <...原创 2020-03-08 14:10:18 · 188 阅读 · 0 评论 -
【LeetCode 1140】 Stone Game II
题目描述Alex 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 the game ...原创 2020-03-07 23:13:05 · 96 阅读 · 0 评论 -
【LeetCode 1125】 Smallest Sufficient Team
题目描述In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.Consider a sufficient team: a set of peopl...原创 2020-03-07 14:30:57 · 273 阅读 · 0 评论 -
【LeetCode 1105】 Filling Bookcase Shelves
题目描述We 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 shelf_width.We choo...原创 2020-03-06 23:56:44 · 165 阅读 · 0 评论 -
【LeetCode 1092】 Shortest Common Supersequence
题目描述Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If multiple answers exist, you may return any of them.(A string S is a subsequence of st...原创 2020-03-06 22:30:32 · 193 阅读 · 0 评论 -
【LeetCode 1155】 Number of Dice Rolls With Target Sum
题目描述Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If multiple answers exist, you may return any of them.(A string S is a subsequence of st...原创 2020-03-06 19:18:29 · 189 阅读 · 0 评论 -
【LeetCode 1043】 Partition Array for Maximum Sum
题目描述Given an integer array A, you partition the array into (contiguous) subarrays of length at most K. After partitioning, each subarray has their values changed to become the maximum value of that ...原创 2020-03-06 18:46:19 · 129 阅读 · 0 评论 -
【LeetCode 1024】 Video Stitching
题目描述You are given a series of video clips from a sporting event that lasted T seconds. These video clips can be overlapping with each other and have varied lengths.Each video clip clips[i] is an in...原创 2020-03-06 12:01:24 · 150 阅读 · 1 评论 -
【LeetCode 901】 Online Stock Span
题目描述Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock’s price for the current day.The span of the stock’s price today is defined as the ...原创 2020-03-05 20:29:09 · 155 阅读 · 0 评论 -
【LeetCode 1000】 Minimum Cost to Merge Stones
题目描述There are N piles of stones arranged in a row. The i-th pile has stones[i] stones.A move consists of merging exactly K consecutive piles into one pile, and the cost of this move is equal to the...原创 2020-03-05 19:30:53 · 275 阅读 · 0 评论 -
【LeetCode 975】 Odd Even Jump
题目描述You are given an integer array A. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, …) jumps in the series are called odd numbered jumps, and the (2nd, 4th, 6th, …) ...原创 2020-03-05 16:01:58 · 142 阅读 · 0 评论 -
【LeetCode 980】 Unique Paths III
题目描述On a 2-dimensional grid, there are 4 types of squares:1 represents the starting square. There is exactly one starting square.2 represents the ending square. There is exactly one ending square...原创 2020-03-05 01:59:27 · 124 阅读 · 0 评论 -
【LeetCode 964】 Least Operators to Express Number
题目描述Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x … where each operator op1, op2, etc. is either addition, subtraction, multiplication, or divis...原创 2020-03-05 00:23:26 · 241 阅读 · 0 评论 -
【LeetCode 956】Tallest Billboard
题目描述You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.You have a colle...原创 2020-03-04 17:51:18 · 191 阅读 · 1 评论 -
【LeetCode 943】 Find the Shortest Superstring
题目描述Given an array A of strings, find any smallest string that contains each string in A as a substring.We may assume that no string in A is substring of another string in A.Example 1:Input: ["ale...原创 2020-03-04 14:27:05 · 271 阅读 · 0 评论 -
【LeetCode 935】 Knight Dialer
题目描述A chess knight can move as indicated in the chess diagram below:.This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makes N-1 hops. Each ...原创 2020-03-03 19:03:56 · 130 阅读 · 0 评论 -
【LeetCode 926】 Flip String to Monotone Increasing
题目描述A string of '0’s and '1’s is monotone increasing if it consists of some number of '0’s (possibly 0), followed by some number of '1’s (also possibly 0.)We are given a string S of '0’s and '1’s, a...原创 2020-03-03 16:56:31 · 107 阅读 · 0 评论 -
【LeetCode 898】 Bitwise ORs of Subarrays
题目描述We 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, obtaining a result A[i]...原创 2020-03-03 16:26:55 · 168 阅读 · 1 评论 -
【LeetCode 546】 Remove Boxes
题目描述Given several boxes with different colors represented by different positive numbers.You may experience several rounds to remove boxes until there is no box left. Each time you can choose some co...原创 2020-02-28 23:16:56 · 96 阅读 · 0 评论 -
【LeetCode 877】 Stone Game
题目描述Alex and Lee play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].The objective of the game is t...原创 2020-02-28 19:04:04 · 125 阅读 · 0 评论 -
【LeetCode 879】 Profitable Schemes
题目描述There are G people in a gang, and a list of various crimes they could commit.The i-th crime generates a profit[i] and requires group[i] gang members to participate.If a gang member participates...原创 2020-02-28 18:11:35 · 131 阅读 · 0 评论 -
【LeetCode 873】 Length of Longest Fibonacci Subsequence
题目描述A 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 integers forming a sequence, find the len...原创 2020-02-28 13:54:30 · 132 阅读 · 0 评论 -
【LeetCode 712】 Minimum ASCII Delete Sum for Two Strings
题目描述Given two strings s1, 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" adds...原创 2020-02-28 12:39:31 · 89 阅读 · 0 评论 -
【LeetCode 115】 Distinct Subsequences
题目描述Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some...原创 2020-02-27 23:53:28 · 87 阅读 · 0 评论 -
【LeetCode 871】 Minimum Number of Refueling Stops
题目描述A car travels from a starting position to a destination which is target miles east of the starting position.Along the way, there are gas stations. Each station[i] represents a gas station that ...原创 2020-02-27 22:23:03 · 133 阅读 · 0 评论 -
【LeetCode 576】 Out of Boundary Paths
题目描述There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary in four directions (up, down, left, right). Ho...原创 2020-02-27 18:39:07 · 151 阅读 · 0 评论 -
【LeetCode 329】 Longest Increasing Path in a Matrix
题目描述Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outsi...原创 2020-02-26 23:22:26 · 86 阅读 · 0 评论