Compare commits

...

2 Commits

Author SHA1 Message Date
4144e8d7d3 128. 最长连续序列 2025-08-11 11:15:13 +08:00
2d390fedb8 49. 字母异位词分组 2025-08-09 22:31:05 +08:00
2 changed files with 37 additions and 0 deletions

16
test002.cpp Normal file
View File

@@ -0,0 +1,16 @@
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
unordered_map<string, vector<string>> data;
for(const auto &s : strs){
auto key = s;
sort(key.begin(), key.end());
data[key].push_back(s);
}
vector<vector<string>> ret;
for(const auto &line : data){
ret.push_back(line.second);
}
return ret;
}
};

21
test003.cpp Normal file
View File

@@ -0,0 +1,21 @@
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
unordered_map <int, int> data;
for(int x:nums) data[x] = 1;
int res = 0;
for(auto &n:data){
if(n.second){
int val = n.first; int len = 1;
for(int i = 1; data.count(val - i)&&data[val - i]; i++){
data[val - i] = 0; len++;
}
for(int i = 1; data.count(val + i)&&data[val + i]; i++){
data[val + i] = 0; len++;
}
res = max(len, res);
}
}
return res;
}
};