03 2025 档案

摘要:44. 通配符匹配 f[0][j]可能会匹配,而f[i][0]一定不匹配,所以i从0开始,而j从1开始即可 class Solution { public: bool isMatch(string s, string p) { int n = s.size(), m = p.size(); s = 阅读全文
posted @ 2025-03-13 16:14 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:43. 字符串相乘 class Solution { public: string multiply(string num1, string num2) { vector<int> A, B; int n = num1.size(), m = num2.size(); for(int i = n - 阅读全文
posted @ 2025-03-13 15:53 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:42. 接雨水 每当插入一个,就要把前面比它小的给删去,因为能存水,最后存有绿色的 class Solution { public: int trap(vector<int>& height) { stack<int> stk; int res = 0; for(int i = 0; i < hei 阅读全文
posted @ 2025-03-13 15:38 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:60. 排列序列 使用next_permutation O(n!k) class Solution { public: string getPermutation(int n, int k) { string res; for(int i = 1; i <= n; ++i) res += to_st 阅读全文
posted @ 2025-03-12 21:43 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:57. 插入区间 class Solution { public: vector<vector<int>> insert(vector<vector<int>>& intervals, vector<int>& newInterval) { vector<vector<int>> res; int 阅读全文
posted @ 2025-03-12 21:19 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:56. 合并区间 class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { vector<vector<int>> res; sort(intervals.begin(), interva 阅读全文
posted @ 2025-03-12 21:18 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:55. 跳跃游戏 class Solution { public: bool canJump(vector<int>& nums) { //顺序遍历,中途断则跳不到 for(int i = 0, maxlen = 0; i < nums.size(); ++i){ if(maxlen < i) re 阅读全文
posted @ 2025-03-12 20:43 awei040519 阅读(5) 评论(0) 推荐(0) 编辑
摘要:54. 螺旋矩阵 class Solution { public: vector<int> spiralOrder(vector<vector<int>>& matrix) { vector<int> ans; if(matrix.empty()) return ans; int u = 0, d 阅读全文
posted @ 2025-03-12 20:34 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:53. 最大子数组和 DP class Solution { public: int maxSubArray(vector<int>& nums) { int res = INT_MIN; for(int i = 0, last = 0; i < nums.size(); ++i){ last = 阅读全文
posted @ 2025-03-12 20:23 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:51. N 皇后 class Solution { public: int m; vector<bool> col, dg, udg; vector<vector<string>> ans; vector<string> path; vector<vector<string>> solveNQuee 阅读全文
posted @ 2025-03-12 20:06 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:98. 验证二叉搜索树 中序遍历 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), l 阅读全文
posted @ 2025-03-12 11:38 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:97. 交错字符串 class Solution { public: bool isInterleave(string s1, string s2, string s3) { int n = s1.size(), m = s2.size(); if(s3.size() != n + m) retur 阅读全文
posted @ 2025-03-12 11:18 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:96. 不同的二叉搜索树 长度一样方案数也会一样,所以可以使用递推式做 图中为f(j-1)*f(i-j) class Solution { public: int numTrees(int n) { vector<int> f(n + 1); f[0] = 1; //f代表固定长度的二叉搜索树种类 阅读全文
posted @ 2025-03-12 11:03 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:95. 不同的二叉搜索树 II 二叉搜索树中序遍历是有序的 枚举中间点k,左子树必然是l,k-1,右子树必然是k+1,r,然后递归求解左右子树各自多少种情况 /** * Definition for a binary tree node. * struct TreeNode { * int val; 阅读全文
posted @ 2025-03-12 09:18 awei040519 阅读(4) 评论(0) 推荐(0) 编辑
摘要:94. 二叉树的中序遍历 dfs写法 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), 阅读全文
posted @ 2025-03-11 21:36 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:93. 复原 IP 地址 class Solution { public: vector<string> res; vector<string> restoreIpAddresses(string s) { dfs(s, 0, 0, ""); return res; } //u第几位开始搜,k已经搜 阅读全文
posted @ 2025-03-11 21:23 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:91. 解码方法 class Solution { public: int numDecodings(string s) { int n = s.size(); s = ' ' + s; vector<int> f(n + 1); f[0] = 1; for(int i = 1; i <= n; + 阅读全文
posted @ 2025-03-11 21:01 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:子集 II 因为元素可能会重复,且要求输出的组合不能重复,所以不能像子集再使用二进制方式去枚举 class Solution { public: vector<vector<int>> ans; vector<int> path; vector<vector<int>> subsetsWithDup 阅读全文
posted @ 2025-03-11 20:48 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:89. 格雷编码 找规律,例如k位格雷码,对k-1位格雷码进行镜像对称,在前半部分末尾补0,后半部分末尾补1即可得到k位格雷码 class Solution { public: vector<int> grayCode(int n) { vector<int> res(1, 0); while(n- 阅读全文
posted @ 2025-03-11 20:11 awei040519 阅读(7) 评论(0) 推荐(0) 编辑
摘要:85. 最大矩形 单调栈思想,在基准线上寻找往上连续的1的最大值 class Solution { public: int maxv(vector<int>& heights){ int n = heights.size(); vector<int> left(n), right(n); stack 阅读全文
posted @ 2025-03-11 18:25 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:84. 柱状图中最大的矩形 单调栈可以解决找到一个数左边或者右边离他最近的比他还要小的数 class Solution { public: int largestRectangleArea(vector<int>& heights) { int n = heights.size(); //存储最多能 阅读全文
posted @ 2025-03-11 16:50 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:81. 搜索旋转排序数组 II 将相等的部分删除再二分 class Solution { public: bool search(vector<int>& nums, int target) { int R = nums.size() - 1; while(R >= 0 && nums[R] == 阅读全文
posted @ 2025-03-11 16:00 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:80. 删除有序数组中的重复项 II class Solution { public: int removeDuplicates(vector<int>& nums) { int k = 0; for(auto &c: nums){ if(k < 2 || nums[k-1] != c || num 阅读全文
posted @ 2025-03-11 15:21 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:78. 子集 二进制 class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { int n = nums.size(); vector<vector<int>> ans; for(int i = 0; i < 阅读全文
posted @ 2025-03-11 14:59 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:77. 组合 class Solution { public: vector<vector<int>> ans; vector<int> path; vector<vector<int>> combine(int n, int k) { dfs(n, k, 1); return ans; } voi 阅读全文
posted @ 2025-03-11 14:48 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:76. 最小覆盖子串 可以使用滑动窗口和双指针需要满足单调性的条件,枚举字符串重点位置i可知i往后走的话,j一定不会往前走 class Solution { public: string minWindow(string s, string t) { unordered_map<char, int> 阅读全文
posted @ 2025-03-10 22:04 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int minDistance(string word1, string word2) { int n = word1.size(), m = word2.size(); word1 = " " + word1; word2 = " " + word 阅读全文
posted @ 2025-03-10 20:53 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:71. 简化路径 class Solution { public: string simplifyPath(string path) { string res, name; if(path.size() != '/') path += '/'; for(auto c : path){ if(c != 阅读全文
posted @ 2025-03-10 20:17 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:68. 文本左右对齐 class Solution { public: vector<string> fullJustify(vector<string>& words, int maxWidth) { //最后一行左对齐,或者这一行只包含一个单词左对齐 //包含多个单词 左右对齐 //先统计能放多 阅读全文
posted @ 2025-03-09 21:12 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:67. 二进制求和 class Solution { public: string addBinary(string a, string b) { reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); string c; int t = 阅读全文
posted @ 2025-03-08 15:46 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:66. 加一 class Solution { public: vector<int> plusOne(vector<int>& digits) { reverse(digits.begin(), digits.end()); int t = 1; for(auto &x : digits){ t 阅读全文
posted @ 2025-03-08 15:40 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:63. 不同路径 II class Solution { public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m = obstacleGrid.size(); int n = obstacleGr 阅读全文
posted @ 2025-03-08 15:22 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:61. 旋转链表 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode( 阅读全文
posted @ 2025-03-08 15:05 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:L2-044 大众情人 #include <bits/stdc++.h> using namespace std; int n, k; vector<int> man, woman; int dis[510][510]; map<int, set<int>> mp; void find(){ for 阅读全文
posted @ 2025-03-08 14:25 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:L2-043 龙龙送外卖 #include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, m; int p[MAXN], f[MAXN]; int maxv; //从u结点走,向根节点(已经经过的结点)走了d 阅读全文
posted @ 2025-03-08 11:34 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:L2-041 插松枝 // # 用队列来模拟传送带,用栈来模拟盒子。 #include <bits/stdc++.h> using namespace std; int n, m, k; stack<int> S; queue<int> Q; signed main(){ cin >> n >> m 阅读全文
posted @ 2025-03-07 20:39 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:L2-042 老板的作息表 #include <bits/stdc++.h> using namespace std; typedef pair<string, string> PII; set<PII> record; string st, ed; int main(){ cin >> st; w 阅读全文
posted @ 2025-03-07 19:44 awei040519 阅读(3) 评论(0) 推荐(0) 编辑
摘要:link 此题有坑,需要找到病毒源头,0并不一定是 #include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int h[MAXN], e[MAXN], ne[MAXN], idx; int st[MAXN], p[ 阅读全文
posted @ 2025-03-07 17:44 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int a[MAXN], num[MAXN], yifu[MAXN]; int A, B; bool isprime(int n){ if(n == 阅读全文
posted @ 2025-03-07 11:01 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; typedef pair<string, int> PII; map<string, PII> mp; const int MAXN = 100010; int n; string check(st 阅读全文
posted @ 2025-03-07 10:50 awei040519 阅读(6) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; int post[40], dfs[40]; int n, cnt = 1; void backtracking(int index){ if(index > n) return; backtrac 阅读全文
posted @ 2025-03-06 21:12 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int MAXN = 1100; int n, m, k; int st[MAXN]; int main(){ cin >> n >> m >> k; while(k--){ int f 阅读全文
posted @ 2025-03-06 20:53 awei040519 阅读(3) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int N = 10010; int n, m; vector<int> g[N]; int deg[N], backup[N]; void check(){ for(int i = 1 阅读全文
posted @ 2025-03-06 20:07 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int MAXN = 510; int g[MAXN][MAXN]; int color[MAXN]; int n, m, k; int num; bool check(int i){ 阅读全文
posted @ 2025-03-06 19:35 awei040519 阅读(2) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int MAXN = 100010; struct Node{ int begin, val, next; }node[MAXN]; int nbegin, n; vector<Node 阅读全文
posted @ 2025-03-06 19:18 awei040519 阅读(1) 评论(0) 推荐(0) 编辑
摘要:#include <bits/stdc++.h> using namespace std; const int MAXN = 200010; int n; int dis[MAXN]; bool exist[MAXN]; struct Person{ int fid, mid; char sex; 阅读全文
posted @ 2025-03-06 16:36 awei040519 阅读(0) 评论(0) 推荐(0) 编辑
摘要:link 必须要车号⼤的先出,⼩的后出。所以列车排队的每⼀队必须是从⼤到⼩排列(从右往左看),才能保证开出去的车也是从⼤到⼩的。对于每⼀个想要进⼊并列铁轨的车,如果车号⼤于每⼀队的队尾的车号,说明不能进⼊已经有的队伍,必须进⼊新的铁轨,否则,选择⼀个最接近它车号的尾部车号的队伍进⼊。其实⽆需保存每⼀ 阅读全文
posted @ 2025-03-06 15:56 awei040519 阅读(6) 评论(0) 推荐(0) 编辑
摘要:link #include <bits/stdc++.h> using namespace std; const int N = 1010; int n, T, D, E; vector<int> q[N]; bool st[N]; // 剩余数 = 总数 - 掉落数 - 疏果数 int get(v 阅读全文
posted @ 2025-03-04 19:56 awei040519 阅读(0) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示