摘要: 接雨水 class Solution { public: int trap(vector& height) { int ret = 0; stack st; st.push(0); for(int i = 1; i < height.size(); ++i) { if(height[i] <= he 阅读全文
posted @ 2024-10-13 14:30 ikun1111 阅读(16) 评论(0) 推荐(0)
摘要: 每日温度 class Solution { public: vector dailyTemperatures(vector& temperatures) { stack st; vector answer(temperatures.size(), 0); st.push(0); for(int i 阅读全文
posted @ 2024-10-13 14:27 ikun1111 阅读(37) 评论(0) 推荐(0)
摘要: 回文子串 class Solution { public: int countSubstrings(string s) { int ret = 0; vector<vector> dp(s.size(), vector(s.size(), 0)); for(int i = s.size() - 1; 阅读全文
posted @ 2024-10-13 14:23 ikun1111 阅读(26) 评论(0) 推荐(0)
摘要: 不同的子序列 class Solution { public: int numDistinct(string s, string t) { vector<vector<uint64_t>> dp(s.size()+1, vector<uint64_t>(t.size()+1, 0)); for(in 阅读全文
posted @ 2024-10-13 11:35 ikun1111 阅读(17) 评论(0) 推荐(0)
摘要: 最长公共子序列 class Solution { public: int longestCommonSubsequence(string text1, string text2) { vector<vector> dp(text1.size()+1, vector(text2.size()+1, 0 阅读全文
posted @ 2024-10-13 11:32 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 最长递增子序列 class Solution { public: int lengthOfLIS(vector& nums) { if (nums.size() <= 1) return nums.size(); vector dp(nums.size(), 1); dp[0] = 1; int r 阅读全文
posted @ 2024-10-13 11:24 ikun1111 阅读(14) 评论(0) 推荐(0)
摘要: 买卖股票最佳时机IV class Solution { public: int maxProfit(int k, vector& prices) { vector<vector> dp(prices.size(), vector(2k, 0)); for(int i = 0; i < 2k; i++ 阅读全文
posted @ 2024-10-13 11:19 ikun1111 阅读(16) 评论(0) 推荐(0)
摘要: 买卖股票最佳时机 class Solution { public: int maxProfit(vector& prices) { vector<vector> dp(prices.size(), vector(2,0)); dp[0][0] = -prices[0]; dp[0][1] = 0; 阅读全文
posted @ 2024-10-13 11:14 ikun1111 阅读(9) 评论(0) 推荐(0)
摘要: 打家劫舍 class Solution { public: int rob(vector& nums) { if (nums.size() == 0) return 0; if (nums.size() == 1) return nums[0]; vector dp(nums.size(), 0); 阅读全文
posted @ 2024-10-13 11:09 ikun1111 阅读(8) 评论(0) 推荐(0)
摘要: 322 零钱兑换 class Solution { public: int coinChange(vector& coins, int amount) { vector dp(amount+1, INT_MAX); dp[0] = 0; for(int i = 0; i < coins.size() 阅读全文
posted @ 2024-10-13 11:06 ikun1111 阅读(21) 评论(0) 推荐(0)
摘要: 518 零钱兑换II class Solution { public: int change(int amount, vector& coins) { vector<int> dp(5001, 0); dp[0] = 1; for(int i = 0; i < coins.size(); ++i) 阅读全文
posted @ 2024-10-13 11:02 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 1049 最后一块石头的重量II class Solution { public: int lastStoneWeightII(vector& stones) { int sum = 0; for(int &it : stones) { sum += it; } int target = sum / 阅读全文
posted @ 2024-10-13 10:53 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 416 分割等和子集 class Solution { public: bool canPartition(vector& nums) { int sum = 0; for(int &it : nums) { sum += it; } if(sum % 2 == 1) { return false; 阅读全文
posted @ 2024-10-13 10:46 ikun1111 阅读(14) 评论(0) 推荐(0)
摘要: 62 不同路径 class Solution { public: int uniquePaths(int m, int n) { vector<vector> dp(m, vector(n, 0)); if(m <= 1) { return m; } if(n <= 1) { return n; } 阅读全文
posted @ 2024-10-13 10:43 ikun1111 阅读(14) 评论(0) 推荐(0)
摘要: 509 斐波拉契数 class Solution { public: int fib(int n) { if(n <= 1) { return n; } vector dp(n+1); dp[0] = 0; dp[1] = 1; for(int i = 2; i <= n; ++i) { dp[i] 阅读全文
posted @ 2024-10-13 10:38 ikun1111 阅读(10) 评论(0) 推荐(0)