随笔分类 - Week7 基本数据结构
摘要:1 // [1,3],[4,7],[9,9] 2 // L[1] = 3,L[4] = 7,L[9] = 9; 3 // R[3] = 1,R[7] = 4,R[9] = 9; 4 class SummaryRanges 5 { 6 map<int,int> L,R; 7 unordered_set
阅读全文
摘要:1 class MedianFinder 2 { 3 priority_queue<int,vector<int>,greater<int>> up;//小根堆 4 priority_queue<int> down;//大根堆 5 public: 6 MedianFinder() {} 7 8 vo
阅读全文
摘要:1 class Solution 2 { 3 struct cmp 4 { 5 bool operator()(pair<string,int> const &left,pair<string,int> const &right) 6 { 7 if(left.second == right.seco
阅读全文
摘要:1 class UnionFind 2 { 3 public: 4 vector<int> parent; // 存储若干棵树 5 int count; 6 UnionFind(int n) 7 { 8 count = n; 9 for (int i = 0; i < n; i++) parent.
阅读全文
摘要:1 class Solution 2 { 3 vector<int> p; 4 5 int find(int x) 6 { 7 if(p[x] != x) p[x] = find(p[x]); 8 return p[x]; 9 } 10 public: 11 int findCircleNum(ve
阅读全文
摘要:1 class Solution 2 { 3 public: 4 int subarraySum(vector<int>& nums, int k) 5 { 6 unordered_map<int,int> hash; 7 hash[0] = 1; 8 9 int res = 0; 10 for(i
阅读全文
摘要:1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x),
阅读全文
摘要:1 //开放寻址法 2 class MyHashMap 3 { 4 public: 5 const static int N = 2000003; 6 int hash_key[N], hash_value[N]; 7 8 MyHashMap() 9 { 10 memset(hash_key, -1
阅读全文
摘要:1 class Solution 2 { 3 public: 4 vector<string> findRepeatedDnaSequences(string s) 5 { 6 int n = s.size(); 7 vector<string> res; 8 unordered_map<strin
阅读全文
摘要:https://leetcode-cn.com/problems/two-sum/ 1 //哈希表 2 class Solution 3 { 4 public: 5 vector<int> twoSum(vector<int>& nums, int target) 6 { 7 unordered_m
阅读全文

浙公网安备 33010602011771号