动态规划
xiaocong1990
这个作者很懒,什么都没留下…
展开
-
[leetcode]minimum-cost-to-reach-destination-in-time 规定时间内到达终点的最小费用
【代码】[leetcode]minimum-cost-to-reach-destination-in-time 规定时间内到达终点的最小费用。原创 2024-07-10 14:23:58 · 229 阅读 · 0 评论 -
[leetcode] car-pooling 拼车
【代码】[leetcode] car-pooling 拼车。原创 2024-07-10 10:34:59 · 196 阅读 · 0 评论 -
[leetcode] largest-divisible-subset 最大整除子集
【代码】[leetcode] largest-divisible-subset 最大整除子集。原创 2024-07-10 10:15:48 · 147 阅读 · 0 评论 -
[leetcode]542. 01 Matrix
题目链接:https://leetcode.com/problems/01-matrix/#/descriptionGiven a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.原创 2017-05-16 11:20:07 · 273 阅读 · 1 评论 -
[leetcode] n个骰子的点数
【代码】[leetcode] n个骰子的点数。原创 2024-07-01 10:58:43 · 200 阅读 · 0 评论 -
[leetcode]longest-arithmetic-subsequence-of-given-difference. 最长定差子序列
【代码】[leetcode]longest-arithmetic-subsequence-of-given-difference. 最长定差子序列。原创 2024-06-28 18:32:29 · 304 阅读 · 0 评论 -
[leetcode]number-of-longest-increasing-subsequence
【代码】[leetcode]number-of-longest-increasing-subsequence。原创 2024-06-26 11:14:19 · 275 阅读 · 0 评论 -
[leetcode]number-of-longest-increasing-subsequence
【代码】[leetcode]number-of-longest-increasing-subsequence。原创 2024-06-26 11:11:39 · 250 阅读 · 0 评论 -
[leetcode]unique-paths 不同路径
【代码】[leetcode]unique-paths 不同路径。原创 2024-06-24 18:46:30 · 234 阅读 · 0 评论 -
[leetcode]718. 最长重复子数组 maximum-length-of-repeated-subarray
长度最长的公共子数组是 [3,2,1]。、长度最长的子数组的长度。原创 2024-06-10 11:03:36 · 205 阅读 · 0 评论 -
[leetcode]第 n个丑数
我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。输入: n = 10。n 不超过1690。原创 2024-05-20 21:13:17 · 253 阅读 · 0 评论 -
[leetcode]238. Product of Array Except Self
题目链接:https://leetcode.com/problems/product-of-array-except-self/Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the原创 2017-01-08 19:57:08 · 247 阅读 · 1 评论 -
[lintcode]640. 编辑距离 II
链接:http://www.lintcode.com/zh-cn/problem/edit-distance-ii/给你两个字符串 S 和 T, 判断他们是否只差一步编辑。您在真实的面试中是否遇到过这个题?Yes样例给你字符串 s ="aDb", t="adb"返回true思路:首先对于这道...原创 2018-04-18 14:25:48 · 282 阅读 · 0 评论 -
【leetcode】最长公共子序列
链接:力扣给定两个字符串text1 和text2,返回这两个字符串的最长 公共子序列 的长度。如果不存在 公共子序列 ,返回 0 。一个字符串的子序列是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。例如,"ace" 是 "abcde" 的子序列,但 "aec" 不是 "abcde" 的子序列。两个字符串的 公共子序列 是这两个字符串所共同拥有的子序列。示例 1:输入:text1 = "abcde...原创 2022-01-10 22:00:36 · 148 阅读 · 0 评论 -
[leetcode] 122. Best Time to Buy and Sell Stock II
链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/submissions/You are given an arraypriceswhereprices[i]is the price of a given stock on theithday.Find the maximum profit you can achieve. You may complete as many transactions a...原创 2021-05-08 13:26:10 · 111 阅读 · 0 评论 -
[leetcode]329. Longest Increasing Path in a Matrix
题目链接:https://leetcode.com/problems/longest-increasing-path-in-a-matrix/#/descriptionGiven an integer matrix, find the length of the longest increasing path.From each cell, you can either mov原创 2017-06-28 21:28:47 · 248 阅读 · 0 评论 -
[网易]合唱团
有 n 个学生站成一排,每个学生有一个能力值,牛牛想从这 n 个学生中按照顺序选取 k 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 k 个学生的能力值的乘积最大,你能返回最大的乘积吗?输入描述:每个输入包含 1 个测试用例。每个测试数据的第一行包含一个整数 n (1 i(-50 输出描述:输出一行表示最大的乘积。输入例子:37原创 2018-04-02 16:49:22 · 154 阅读 · 0 评论 -
[lintcode]909. Android Unlock Patterns
链接:http://www.lintcode.com/zh-cn/problem/android-unlock-patterns/Given an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock pa原创 2018-03-24 20:33:30 · 436 阅读 · 0 评论 -
[lintcode]889. Sentence Screen Fitting
链接:http://www.lintcode.com/zh-cn/problem/sentence-screen-fitting/ Given a rows x cols screen and a sentence represented by a list of non-empty words, find how many times the given sentence can ...原创 2018-03-24 18:55:00 · 370 阅读 · 0 评论 -
[lintcode]867. 4 Keys Keyboard
链接:http://www.lintcode.com/zh-cn/problem/4-keys-keyboard/Imagine you have a special keyboard with the following keys:Key 1: (A): Print one 'A' on screen.Key 2: (Ctrl-A): Select the who原创 2018-03-24 17:18:11 · 323 阅读 · 0 评论 -
[lintcode]843. 数字翻转
链接:http://www.lintcode.com/zh-cn/problem/digital-flip/给你一个01构成的数组。请你找出最小翻转步数,使得数组满足以下规则:1的后面可以是1或者0,但是0的后面必须是0。 注意事项输入的数组长度n 。您在真实的面试中是否遇到过这个题? Yes样例原创 2018-03-24 16:41:29 · 716 阅读 · 0 评论 -
[lintcode]752. 流浪剑客斯温
链接:http://www.lintcode.com/zh-cn/problem/rogue-knight-sven/在物质位面“现实”中,有n+1个星球,分别为星球0,星球1,……,星球n。每一个星球都有一个传送门,通过传送门可以直接到达目标星球而不经过其他的星球。不过传送门有两个缺点。第一,从星球i通过传送门只能到达编号比i大,且与i的差不超过limit的星球。原创 2018-03-24 16:02:27 · 435 阅读 · 0 评论 -
[lintcode]741. Calculate Maximum Value II
链接:http://www.lintcode.com/zh-cn/problem/calculate-maximum-value-ii/Given a string of numbers, write a function to find the maximum value from the string, you can add a + or * sign between any t原创 2018-03-24 15:28:48 · 207 阅读 · 0 评论 -
[lintcode]740. 零钱兑换II
链接:http://www.lintcode.com/zh-cn/problem/coin-change-ii/#给出不同面值的硬币以及总金额. 试写一函数来计算构成该总额的组合数量. 你可以假设每一种硬币你都有无限个.class Solution {public: /** * @param amount: a total amount of money原创 2018-03-24 15:01:31 · 831 阅读 · 0 评论 -
[lintcode]118. 不同的子序列
链接:http://www.lintcode.com/zh-cn/problem/distinct-subsequences/给出字符串S和字符串T,计算S的不同的子序列中T出现的个数。子序列字符串是原始字符串通过删除一些(或零个)产生的一个新的字符串,并且对剩下的字符的相对位置没有影响。(比如,“ACE”是“ABCDE”的子序列字符串,而“AEC”不是)。您在真实的面试中是否遇到过这个题?Y...原创 2018-03-20 14:54:37 · 849 阅读 · 1 评论 -
[lintcode]91. 最小调整代价
链接:http://www.lintcode.com/zh-cn/problem/minimum-adjustment-cost/Given an integer array, adjust each integers so that the difference of every adjacent integers are not greater than a given number...原创 2018-03-19 16:42:22 · 511 阅读 · 0 评论 -
[leetcode]546. Remove Boxes
题目链接:https://leetcode.com/problems/remove-boxes/description/Given several boxes with different colors represented by different positive numbers. You may experience several rounds to remove box原创 2017-08-13 21:56:33 · 1372 阅读 · 0 评论 -
[lintcode]29. 交叉字符串
链接:http://www.lintcode.com/zh-cn/problem/interleaving-string/ 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 您在真实的面试中是否遇到过这个题? Yes样例比如 s1 = "aabcc" s2 = "dbbca" - 当 s3 = "aadbbcbcac",返回 tru...原创 2018-03-19 16:40:31 · 315 阅读 · 0 评论 -
[lintcode]108. 分割回文串 II
链接:http://www.lintcode.com/zh-cn/problem/palindrome-partitioning-ii/ 给定一个字符串s,将s分割成一些子串,使每个子串都是回文。返回s符合要求的的最少分割次数。您在真实的面试中是否遇到过这个题?Yes样例比如,给出字符串s = "aab",返回 1, 因为进行一次分割可以将字符串s分割成["a...原创 2018-03-20 12:52:36 · 272 阅读 · 0 评论 -
[leetcode]629. K Inverse Pairs Array
链接:https://leetcode.com/problems/k-inverse-pairs-array/description/Given two integers n and k, find how many different arrays consist of numbers from 1 to n such that there are exactly k inverse pairs...原创 2018-05-18 20:28:46 · 176 阅读 · 0 评论 -
[leetcode]818. Race Car
链接:https://leetcode.com/problems/race-car/description/Your car starts at position 0 and speed +1 on an infinite number line. (Your car can go into negative positions.)Your car drives automatically ac...原创 2018-05-19 16:30:37 · 617 阅读 · 0 评论 -
[leetcode]44. Wildcard Matching
链接:https://leetcode.com/problems/wildcard-matching/description/ Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*'.'?' Matches any sin...原创 2018-05-13 18:08:28 · 322 阅读 · 0 评论 -
[leetcode]516. Longest Palindromic Subsequence 最长回文子序列
题目链接:https://leetcode.com/problems/longest-palindromic-subsequence/Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000....原创 2017-02-10 23:43:35 · 2148 阅读 · 1 评论 -
[leetcode]638. Shopping Offers
题目链接:https://leetcode.com/problems/shopping-offers/#/descriptionIn LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a specia...原创 2017-07-24 15:43:07 · 348 阅读 · 0 评论 -
[leetcode]525. Contiguous Array
题目链接:https://leetcode.com/problems/contiguous-array/#/descriptionGiven a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]...原创 2017-05-06 11:12:48 · 403 阅读 · 0 评论 -
[leetcode]689. Maximum Sum of 3 Non-Overlapping Subarrays
链接:https://leetcode.com/problems/maximum-sum-of-3-non-overlapping-subarrays/description/In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum.Each subarray ...原创 2018-06-09 17:49:40 · 371 阅读 · 0 评论 -
[leetcode]132. Palindrome Partitioning II
链接:https://leetcode.com/problems/palindrome-partitioning-ii/description/Given a strings, partitionssuch that every substring of the partition is a palindrome.Return the minimum cuts needed for a pa...原创 2018-06-01 21:03:28 · 194 阅读 · 0 评论 -
[leetcode]188. Best Time to Buy and Sell Stock IV
链接:https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/description/Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the m...原创 2018-05-31 17:59:12 · 728 阅读 · 0 评论 -
[leetcode]691. Stickers to Spell Word
链接:https://leetcode.com/problems/stickers-to-spell-word/description/We are given N different types of stickers. Each sticker has a lowercase English word on it.You would like to spell out the given ta...原创 2018-06-13 17:43:52 · 388 阅读 · 0 评论 -
[leetcode]85. Maximal Rectangle
链接:https://leetcode.com/problems/maximal-rectangle/description/Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.Example:Input:[ [...原创 2018-06-09 20:56:23 · 208 阅读 · 0 评论