摘要: 打卡第五十六天 1道简单题+2道中等题 题目: 思路:将问题转换为:某公交车从第1900站做为起点,第2000站做为终点。第i个人表示从第birth[i]站上车,在第death[i] + 1站下车。 题目描述到生于1908年,死于1909年的人应当被列入1908年和1909年的计数,所以第death 阅读全文
posted @ 2025-12-16 00:22 Wy0518 阅读(1) 评论(0) 推荐(0)
摘要: 打卡第五十五天 2道简单题+1道中等题 题目: 思路:差分 代码: class Solution { public: int numberOfPoints(vector<vector<int>>& nums) { int max_end = 0; for (const auto& s : nums) 阅读全文
posted @ 2025-12-15 00:02 Wy0518 阅读(3) 评论(0) 推荐(0)
摘要: 打卡第五十四天 2道中等题 题目: 思路: 代码: class Solution { public: int countSubmatrices(vector<vector<int>> &grid, int k) { int ans = 0, m = grid.size(), n = grid[0]. 阅读全文
posted @ 2025-12-14 00:12 Wy0518 阅读(1) 评论(0) 推荐(0)
摘要: 打卡第五十三天 2道中等题 题目: 思路: 代码: class NumMatrix { vector<vector<int>> sum; public: NumMatrix(vector<vector<int>> &matrix) { int m = matrix.size(), n = matri 阅读全文
posted @ 2025-12-13 00:33 Wy0518 阅读(4) 评论(0) 推荐(0)
摘要: 打卡第五十二天 2道中等题 题目: 思路:前缀和+哈希表 代码: int findMaxLength(vector<int>& nums) { unordered_map<int, int> pos = {{0, -1}}; // 初始前缀和为0,索引为-1(从0开始计算子数组) int ans = 阅读全文
posted @ 2025-12-12 00:36 Wy0518 阅读(3) 评论(0) 推荐(0)
摘要: 打卡第五十一天 2道中等题 题目: 思路:前缀和+哈希表,同余定理 代码: int subarraysDivByK(vector<int>& nums, int k) { unordered_map<int,int> cnt; // 哈希表 int ans = 0, s = 0; // 答案计数、当 阅读全文
posted @ 2025-12-11 00:09 Wy0518 阅读(2) 评论(0) 推荐(0)
摘要: 打卡第五十天 2道中等题 题目: 思路: 代码: class Solution { public: int numOfSubarrays(vector<int>& arr) { const int MODULO = 1000000007; int odd = 0, even = 1; // odd: 阅读全文
posted @ 2025-12-10 00:49 Wy0518 阅读(2) 评论(0) 推荐(0)
摘要: 打卡第四十九天 2道中等题 题目: 思路: 代码: class Solution { public: long long shiftDistance(string s, string t, vector<int>& nextCost, vector<int>& previousCost) { lon 阅读全文
posted @ 2025-12-09 00:17 Wy0518 阅读(4) 评论(0) 推荐(0)
摘要: 打卡第四十八天 2道中等题 题目: 思路:前缀和+贪心,一边遍历数组计算前缀和,一边维护前缀和的最小值(相当于股票最低价格),用当前的前缀和(卖出价格)减去前缀和的最小值(买入价格),就得到了以当前元素结尾的子数组和的最大值(利润),用它来更新答案的最大值(最大利润)。题目要求子数组不能为空,应先计 阅读全文
posted @ 2025-12-08 00:04 Wy0518 阅读(4) 评论(0) 推荐(0)
摘要: 打卡第四十七天 2道简单题+1道中等题 题目: 思路: 代码: class Solution { public: vector<bool> isArraySpecial(vector<int>& nums, vector<vector<int>>& queries) { vector<int> s( 阅读全文
posted @ 2025-12-06 23:36 Wy0518 阅读(3) 评论(0) 推荐(0)