摘要: [Algo] 二维动态规划2 1. 不同的子序列 // 4. 不同的子序列 // https://leetcode.cn/problems/distinct-subsequences/ long numDistinct(string s, string t) { int n = s.length() 阅读全文
posted @ 2025-01-08 17:34 yaoguyuan 阅读(3) 评论(0) 推荐(0)
摘要: [Algo] 二维动态规划 fx1 - 暴力递归, fx2 - 记忆化搜索, fx3 - 严格位置依赖, fx4 - 状态压缩 1. 最小路径和 // 1. 最小路径和 // https://leetcode.cn/problems/minimum-path-sum/description/ int 阅读全文
posted @ 2025-01-07 17:27 yaoguyuan 阅读(9) 评论(0) 推荐(0)
摘要: [Algo] 一维动态规划 fx1 - 暴力递归, fx2 - 自顶向底动态规划(记忆化搜索), fx3 - 自底向顶动态规划(严格位置依赖) 1. 最低票价 // 1. 最低票价 // https://leetcode.cn/problems/minimum-cost-for-tickets/de 阅读全文
posted @ 2025-01-07 17:27 yaoguyuan 阅读(5) 评论(0) 推荐(0)
摘要: [Algo] 洪水填充 1. 被围绕的区域 // 1. 被围绕的区域 // https://leetcode.cn/problems/surrounded-regions/description/ void dfs1(vector<vector<char>>& board, int i, int j 阅读全文
posted @ 2025-01-06 09:33 yaoguyuan 阅读(7) 评论(0) 推荐(0)
摘要: [Algo] 并查集 基本模型: int father[MAXN]; int sets; void build(int n) { for (int i = 0; i < n; i++) father[i] = i; sets = n; } int find(int i) { if (father[i 阅读全文
posted @ 2025-01-06 09:33 yaoguyuan 阅读(1) 评论(0) 推荐(0)
摘要: [Algo] 单调队列 1. 滑动窗口最大值 // 1. 滑动窗口最大值 // https://leetcode.cn/problems/sliding-window-maximum/description/ vector<int> maxSlidingWindow(vector<int>& num 阅读全文
posted @ 2025-01-06 09:33 yaoguyuan 阅读(1) 评论(0) 推荐(0)
摘要: [Algo] 二分答案法 1. 机器人跳跃 // 1. 机器人跳跃 // https://www.nowcoder.com/practice/7037a3d57bbd4336856b8e16a9cafd71 bool complete(int energy, vector<int>& height, 阅读全文
posted @ 2024-12-28 14:35 yaoguyuan 阅读(4) 评论(0) 推荐(0)
摘要: [Algo] 单调栈 基本模板: vector<vector<int>> lessThanIndex(vector<int> &arr) { int len = arr.size(); vector<vector<int>> ans(len, vector<int>(2, 0)); stack<in 阅读全文
posted @ 2024-12-28 14:35 yaoguyuan 阅读(9) 评论(0) 推荐(0)
摘要: [Algo] 双指针 1. 接雨水 // 1. 接雨水 // https://leetcode.cn/problems/trapping-rain-water/ int trap1(vector<int>& height) { vector<int> arr_l, arr_r; arr_l.resi 阅读全文
posted @ 2024-12-28 14:34 yaoguyuan 阅读(2) 评论(0) 推荐(0)
摘要: [Algo] 滑动窗口 1. 长度最小的子数组 // 1. 长度最小的子数组 // https://leetcode.cn/problems/minimum-size-subarray-sum/description/ int minSubArrayLen(int target, vector<in 阅读全文
posted @ 2024-12-22 14:33 yaoguyuan 阅读(11) 评论(0) 推荐(0)