249. Group Shifted Strings
class Solution {
public:
vector<vector<string>> groupStrings(vector<string>& strings) {
unordered_map<string, int> dict;
vector<vector<string>> res;
for (string &s : strings) {
string tmp;
for (int ch:s) tmp += ch - s[0] >= 0 ? (ch - s[0]) % 26 + 'a' : ch - s[0] + 26 + 'a' ;
if (!dict.count(tmp)) {
dict[tmp] = res.size();
res.push_back({});
}
res[dict[tmp]].push_back(s);
}
return res;
}
};