08 2021 档案

摘要:题源:leetcode 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ 比原来的那个最佳买卖股票时机II多了一个情况去进行dp,其他思路一样。 1 class Solution { 阅读全文
posted @ 2021-08-22 13:39 Danae丶 阅读(86) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/longest-increasing-subsequence/ 这类动态规划题目就是考虑目前和之前的大小关系 1 class Solution { 2 public: 3 int lengthOfLIS( 阅读全文
posted @ 2021-08-20 11:13 Danae丶 阅读(40) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/perfect-squares 一道比较简单的动态规划: 1 class Solution { 2 public: 3 int numSquares(int n) { 4 vector<int> f(n 阅读全文
posted @ 2021-08-18 19:22 Danae丶 阅读(51) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/ugly-number-ii/ 考虑使用dp 1 class Solution { 2 public: 3 int nthUglyNumber(int n) { 4 vector<int> dp(n + 阅读全文
posted @ 2021-08-16 13:23 Danae丶 阅读(36) 评论(0) 推荐(0)
摘要:题源:Leetcode 链接:https://leetcode-cn.com/problems/maximal-square/ 1 class Solution { 2 public: 3 int maximalSquare(vector<vector<char>>& matrix) { 4 if 阅读全文
posted @ 2021-08-15 11:10 Danae丶 阅读(69) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/house-robber/ 这道题也是经典的dp类型的题目 1 class Solution { 2 public: 3 int rob(vector<int>& nums) { 4 int size = 阅读全文
posted @ 2021-08-14 10:47 Danae丶 阅读(67) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/word-break/ 这道题目也是用到动态规划,同时考虑使用哈希表的数据结构。 其中check指的是dp[j]后的词是否在哈希表中出现,若出现则dp[i]为true 1 class Solution { 阅读全文
posted @ 2021-08-13 10:53 Danae丶 阅读(65) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/triangle/ 这道题目使用动态规划解决。 1 class Solution { 2 public: 3 int minimumTotal(vector<vector<int>>& triangle) 阅读全文
posted @ 2021-08-12 09:10 Danae丶 阅读(78) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/interleaving-string/ 这道题目可以考虑使用动态规划去完成 我们可以找到他的状态转移方程: 其中这个p为i+j-1。 代码实现如下: 1 class Solution { 2 publi 阅读全文
posted @ 2021-08-11 16:53 Danae丶 阅读(85) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/decode-ways 这也是一道动态规划的题目,注意f(x)和f(x-1)、f(x-2)的关系 1 class Solution { 2 public: 3 int numDecodings(strin 阅读全文
posted @ 2021-08-10 10:43 Danae丶 阅读(73) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/minimum-path-sum/ 还是一道经典的动态规划题 1 class Solution { 2 public: 3 int minPathSum(vector<vector<int>>& grid 阅读全文
posted @ 2021-08-09 09:18 Danae丶 阅读(56) 评论(0) 推荐(0)
摘要:题源:LeetCode 链接:https://leetcode-cn.com/problems/unique-paths-ii/ 其实和上一个随笔中的不同路径一样,只是多了个障碍物,多了个判断的过程。 1 class Solution { 2 public: 3 int uniquePathsWit 阅读全文
posted @ 2021-08-08 09:02 Danae丶 阅读(43) 评论(0) 推荐(0)
摘要:题源:leetcode 链接:https://leetcode-cn.com/problems/unique-paths/ 一道动态规划题,维护一个m*n的数组即可 1 class Solution { 2 public: 3 int uniquePaths(int m, int n) { 4 ve 阅读全文
posted @ 2021-08-06 12:36 Danae丶 阅读(44) 评论(0) 推荐(0)
摘要:题源:leetcode 链接:https://leetcode-cn.com/problems/jump-game-ii/ 这次讨论两种解法,一个dp一个贪心 贪心的方法: 1 class Solution { 2 public: 3 int jump(vector<int>& nums) { 4 阅读全文
posted @ 2021-08-03 16:03 Danae丶 阅读(55) 评论(0) 推荐(0)
摘要:题源:leetcode 链接:https://leetcode-cn.com/problems/longest-palindromic-substring/solution/zui-chang-hui-wen-zi-chuan-by-leetcode-solution/ 动态规划经典题 首先,每一个 阅读全文
posted @ 2021-08-03 09:35 Danae丶 阅读(54) 评论(0) 推荐(0)