Compare commits
2 Commits
c783a5ff9c
...
4144e8d7d3
| Author | SHA1 | Date | |
|---|---|---|---|
| 4144e8d7d3 | |||
| 2d390fedb8 |
16
test002.cpp
Normal file
16
test002.cpp
Normal 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
21
test003.cpp
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user