public ArrayList<String> anagrams(String[] strs) {
        HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
        ArrayList<String> result = new ArrayList<String>();
        for (String str : strs) {
            String min = toSmallest2(str);
            ArrayList<String> tmp = map.get(min);
            if (tmp == null) {
                tmp = new ArrayList<String>();
                map.put(min, tmp);
            }
            tmp.add(str);
        }
        for (ArrayList<String> tmp : map.values()) {
            if (tmp.size() > 1)
                result.addAll(tmp);
        }
        return result;
    }