### 题目

Given a string, we can “shift” each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep “shifting” which forms the sequence:

"abc" -> "bcd" -> ... -> "xyz" Given a list of strings which contains only lowercase alphabets, group all strings that belong to the same shifting sequence.

For example, given: ["abc", "bcd", "acef", "xyz", "az", "ba", "a", "z"], A solution is:

[
["abc","bcd","xyz"],
["az","ba"],
["acef"],
["a","z"]
]


### 用HashMap

#### Java代码

public class Solution {
public List<List<String>> groupStrings(String[] strings) {
Map<String,Integer> dic = new HashMap<>();
List<List<String>> result = new ArrayList<>();
for (String s : strings) {
String std = std(s);
Integer index = dic.get(std);
if (index == null) {
dic.put(std,result.size());
List<String> list = new ArrayList<>(Arrays.asList(new String[]{s}));
} else {
List<String> list = result.get(index);
}
}
return result;
}
// map a string to standard space: start with 'a'
private String std(String s) {
int dis = s.charAt(0) - 'a';
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
char c = (char)(s.charAt(i) - dis);
if (c < 'a') { c += 26; }
sb.append(c);
}
return sb.toString();
}
}