摘要: 打卡第五十四天 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)
摘要: 打卡第四十六天 2道中等题 题目: 思路:前缀和+哈希表 代码: class Solution { public: vector<int> vowelStrings(vector<string>& words, vector<vector<int>>& queries) { int n = word 阅读全文
posted @ 2025-12-06 00:21 Wy0518 阅读(5) 评论(0) 推荐(0)
摘要: 打卡第四十五天 2道中等题 题目: 思路:对网格中的每个位置,分别计算它的两条对角线上不同值的数量,然后计算这两个数量的绝对差。 代码: class Solution { public: vector<vector<int>> differenceOfDistinctValues(vector<ve 阅读全文
posted @ 2025-12-05 00:54 Wy0518 阅读(3) 评论(0) 推荐(0)