摘要: 454. 四数相加 II class Solution { public: int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) { int result = 阅读全文
posted @ 2025-07-03 12:40 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 哈希表: 哈希碰撞 拉链法 线性探测法 常见的三种哈希结构 242. 有效的字母异位词 只有字母,可以用长度为26的定长数组表示。 class Solution { public: bool isAnagram(string s, string t) { array<int, 26> cnt_s{} 阅读全文
posted @ 2025-07-02 19:37 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 42. 接雨水 class Solution { public: int trap(vector<int>& height) { int n = height.size(); stack<int> st; st.push(0); int answer = 0; for(int i = 1; i < 阅读全文
posted @ 2025-07-01 15:41 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 单调栈 739.每日温度 这里用下标进栈,解决日期问题。 class Solution { public: vector<int> dailyTemperatures(vector<int>& temperatures) { int n = temperatures.size(); vector<i 阅读全文
posted @ 2025-06-30 15:52 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 最后一块石头的重量 II class Solution { public: int lastStoneWeightII(vector<int>& stones) { int n = stones.size(); int s = reduce(stones.begin(), stones.end()) 阅读全文
posted @ 2025-02-22 16:47 skyler886 阅读(13) 评论(0) 推荐(0)
摘要: 0-1背包 二维 #include <iostream> #include <vector> using namespace std; int main() { int m, n; cin >> m >> n; vector<int> weight(m + 1, 0); vector<int> va 阅读全文
posted @ 2025-02-16 19:39 skyler886 阅读(6) 评论(0) 推荐(0)
摘要: 不同路径 class Solution { public: int uniquePaths(int m, int n) { int answer = 0; vector<vector<int>> dp(m, vector<int>(n, 0)); for(int i = 0; i < m; i++) 阅读全文
posted @ 2025-02-16 17:29 skyler886 阅读(14) 评论(0) 推荐(0)
摘要: 斐波那契数 class Solution { public: int fib(int n) { if(n == 0) return 0; if(n == 1) return 1; vector<int> dp(n + 1); dp[0] = 0; dp[1] = 1; for(int i = 2;i 阅读全文
posted @ 2025-02-15 22:44 skyler886 阅读(6) 评论(0) 推荐(0)
摘要: 合并区间 class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { sort(intervals.begin(), intervals.end(), [](const vector<int 阅读全文
posted @ 2025-02-15 20:51 skyler886 阅读(8) 评论(0) 推荐(0)
摘要: 用最少数量的箭引爆气球 class Solution { public: int findMinArrowShots(vector<vector<int>>& points) { int answer = 1; sort(points.begin(), points.end(), [](vector 阅读全文
posted @ 2025-02-15 20:41 skyler886 阅读(6) 评论(0) 推荐(0)