-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupShiftedStrings.cc
More file actions
46 lines (39 loc) · 944 Bytes
/
Copy pathGroupShiftedStrings.cc
File metadata and controls
46 lines (39 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <memory.h>
#include <sstream>
#include <iostream>
#include <vector>
#include <cassert>
#include <unordered_map>
using namespace std;
class Solution {
public:
vector<vector<string> > groupStrings(vector<string>& strings) {
unordered_map<string, vector<string> > d;
for (auto i : strings) {
string s = "";
for (auto j : i) {
s += to_string(((j - i[0]) + 26) % 26) + " ";
}
if (d.find(s) != d.end()) {
d[s].push_back(i);
} else {
vector<string> v;
v.push_back(i);
d.insert(pair<string, vector<string> >(s, v));
}
}
vector<vector<string> > result;
for (auto i = d.begin(); i != d.end(); i++) {
sort(i->second.begin(), i->second.end());
result.push_back(i->second);
}
return result;
}
};
int main(int argc, char const* argv[]) {
/* code */
return 0;
}