摘要: 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)
摘要: 738 单调递增的数字 class Solution { public: int monotoneIncreasingDigits(int n) { string str = to_string(n); int flag = str.size(); for(int i = flag - 1; i > 阅读全文
posted @ 2024-10-12 22:06 ikun1111 阅读(9) 评论(0) 推荐(0)
摘要: 452 用最少数量的箭引爆气球 class Solution { public: static bool cmp(const vector &left, const vector &right) { return left[0] < right[0]; } int findMinArrowShots 阅读全文
posted @ 2024-10-12 22:03 ikun1111 阅读(16) 评论(0) 推荐(0)
摘要: 134 加油站 class Solution { public: int canCompleteCircuit(vector& gas, vector& cost) { int currentsum = 0; int totalsum = 0; int start = 0; for(int i = 阅读全文
posted @ 2024-10-12 21:55 ikun1111 阅读(7) 评论(0) 推荐(0)
摘要: 122 买股票最大时机II class Solution { public: int maxProfit(vector& prices) { vector<vector> dp(prices.size(), vector(2,0)); dp[0][0] = -prices[0]; dp[0][1] 阅读全文
posted @ 2024-10-12 21:45 ikun1111 阅读(13) 评论(0) 推荐(0)
摘要: 分发饼干 class Solution { public: int findContentChildren(vector& g, vector& s) { sort(g.begin(), g.end()); sort(s.begin(), s.end()); int count = 0; int i 阅读全文
posted @ 2024-10-12 21:34 ikun1111 阅读(24) 评论(0) 推荐(0)