08 2025 档案
摘要:208. 实现 Trie (前缀树) class TrieNode { public: TrieNode() { isend = false; children.clear(); } bool isend; unordered_map<char, TrieNode*> children; }; cl
        阅读全文
                
摘要:94. 城市间货物运输 I SPFA #include <iostream> #include <vector> #include <list> #include <climits> #include <queue> using namespace std; struct Node { int to
        阅读全文
                
摘要:47. 参加科学大会(第六期模拟笔试) dijkstra(堆优化版)精讲 #include <iostream> #include <vector> #include <climits> #include <queue> #include <list> using namespace std; cl
        阅读全文
                
摘要:53. 寻宝(第七期模拟笔试) prim #include <iostream> #include <vector> #include <climits> using namespace std; int main() { int v, e; cin >> v >> e; int v1, v2 , 
        阅读全文
                
摘要:并查集 int n = 1005; // n根据题目中节点数量而定,一般比节点数量大一点就好 vector<int> father = vector<int> (n, 0); // C++里的一种数组结构 vector<int> rank = vector<int> (n, 1); // 初始每棵树
        阅读全文
                
摘要: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
        阅读全文
                
摘要: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
        阅读全文
                
摘要:99. 岛屿数量 dfs: #include <iostream> #include <vector> using namespace std; int result = 0; vector<vector<int>> dirt = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}
        阅读全文
                
摘要:115. 不同的子序列 class Solution { public: int numDistinct(string s, string t) { int result = 0; vector<vector<uint64_t>> dp(s.size() + 1, vector<uint64_t>(
        阅读全文
                
摘要:718. 最长重复子数组 class Solution { public: int findLength(vector<int>& nums1, vector<int>& nums2) { vector<vector<int>> dp(nums1.size() + 1, vector<int>(nu
        阅读全文
                
摘要:300.最长递增子序列 class Solution { public: int lengthOfLIS(vector<int>& nums) { vector<int> dp(nums.size(), 1); for (int i = 1; i < nums.size(); i++) { for 
        阅读全文
                
摘要:188. 买卖股票的最佳时机 IV class Solution { public: int maxProfit(int k, vector<int>& prices) { if (prices.size() == 0) return 0; vector<vector<int>> dp(prices
        阅读全文
                
摘要:121. 买卖股票的最佳时机 class Solution { public: int maxProfit(vector<int>& prices) { // int low = INT_MAX; // int result = 0; // for (int i = 0; i < prices.si
        阅读全文
                
摘要: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
        阅读全文
                
摘要: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 
        阅读全文
                
摘要:完全背包 #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
        阅读全文
                
摘要:108.将有序数组转换为二叉搜索树 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), 
        阅读全文
                
摘要:701. 二叉搜索树中的插入操作 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), l
        阅读全文
                
摘要:501. 二叉搜索树中的众数 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), lef
        阅读全文
                
                    
                
浙公网安备 33010602011771号