摘要: 接雨水 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)