08 2025 档案

摘要:208. 实现 Trie (前缀树) class TrieNode { public: TrieNode() { isend = false; children.clear(); } bool isend; unordered_map<char, TrieNode*> children; }; cl 阅读全文
posted @ 2025-08-27 09:53 skyler886 阅读(7) 评论(0) 推荐(0)
摘要:94. 城市间货物运输 I SPFA #include <iostream> #include <vector> #include <list> #include <climits> #include <queue> using namespace std; struct Node { int to 阅读全文
posted @ 2025-08-22 19:17 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:47. 参加科学大会(第六期模拟笔试) dijkstra(堆优化版)精讲 #include <iostream> #include <vector> #include <climits> #include <queue> #include <list> using namespace std; cl 阅读全文
posted @ 2025-08-20 15:36 skyler886 阅读(8) 评论(0) 推荐(0)
摘要:53. 寻宝(第七期模拟笔试) prim #include <iostream> #include <vector> #include <climits> using namespace std; int main() { int v, e; cin >> v >> e; int v1, v2 , 阅读全文
posted @ 2025-08-19 12:37 skyler886 阅读(11) 评论(0) 推荐(0)
摘要:并查集 int n = 1005; // n根据题目中节点数量而定,一般比节点数量大一点就好 vector<int> father = vector<int> (n, 0); // C++里的一种数组结构 vector<int> rank = vector<int> (n, 1); // 初始每棵树 阅读全文
posted @ 2025-08-18 11:15 skyler886 阅读(9) 评论(0) 推荐(0)
摘要:106. 岛屿的周长 #include <iostream> #include <vector> #include <queue> using namespace std; int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; int bfs(vector<vect 阅读全文
posted @ 2025-08-17 10:57 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:101. 孤岛的总面积 #include <iostream> #include <vector> #include <queue> using namespace std; int dirt[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; void bfs(vector<v 阅读全文
posted @ 2025-08-16 22:15 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:99. 岛屿数量 dfs: #include <iostream> #include <vector> using namespace std; int result = 0; vector<vector<int>> dirt = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}} 阅读全文
posted @ 2025-08-15 09:51 skyler886 阅读(6) 评论(0) 推荐(0)
摘要:115. 不同的子序列 class Solution { public: int numDistinct(string s, string t) { int result = 0; vector<vector<uint64_t>> dp(s.size() + 1, vector<uint64_t>( 阅读全文
posted @ 2025-08-14 11:44 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:718. 最长重复子数组 class Solution { public: int findLength(vector<int>& nums1, vector<int>& nums2) { vector<vector<int>> dp(nums1.size() + 1, vector<int>(nu 阅读全文
posted @ 2025-08-13 09:52 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:300.最长递增子序列 class Solution { public: int lengthOfLIS(vector<int>& nums) { vector<int> dp(nums.size(), 1); for (int i = 1; i < nums.size(); i++) { for 阅读全文
posted @ 2025-08-12 10:20 skyler886 阅读(4) 评论(0) 推荐(0)
摘要:188. 买卖股票的最佳时机 IV class Solution { public: int maxProfit(int k, vector<int>& prices) { if (prices.size() == 0) return 0; vector<vector<int>> dp(prices 阅读全文
posted @ 2025-08-11 15:49 skyler886 阅读(6) 评论(0) 推荐(0)
摘要:121. 买卖股票的最佳时机 class Solution { public: int maxProfit(vector<int>& prices) { // int low = INT_MAX; // int result = 0; // for (int i = 0; i < prices.si 阅读全文
posted @ 2025-08-09 10:36 skyler886 阅读(5) 评论(0) 推荐(0)
摘要:198. 打家劫舍 class Solution { public: int rob(vector<int>& nums) { if (nums.size() == 0) return 0; if (nums.size() == 1) return nums[0]; vector<int> dp(n 阅读全文
posted @ 2025-08-08 17:02 skyler886 阅读(4) 评论(0) 推荐(0)
摘要:322. 零钱兑换 class Solution { public: int coinChange(vector<int>& coins, int amount) { vector<int> dp(amount + 1, INT_MAX); dp[0] = 0; for (int i = 0; i 阅读全文
posted @ 2025-08-07 10:16 skyler886 阅读(2) 评论(0) 推荐(0)
摘要:完全背包 #include <iostream> #include <vector> using namespace std; int main(){ int n; int v; cin >> n >> v; vector<int> W(n + 1, 0), V(n + 1, 0); for (in 阅读全文
posted @ 2025-08-06 10:47 skyler886 阅读(4) 评论(0) 推荐(0)
摘要:108.将有序数组转换为二叉搜索树 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), 阅读全文
posted @ 2025-08-02 17:14 skyler886 阅读(4) 评论(0) 推荐(0)
摘要:701. 二叉搜索树中的插入操作 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), l 阅读全文
posted @ 2025-08-02 16:36 skyler886 阅读(9) 评论(0) 推荐(0)
摘要:501. 二叉搜索树中的众数 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), lef 阅读全文
posted @ 2025-08-02 11:42 skyler886 阅读(5) 评论(0) 推荐(0)