一、题目

image.png

二、分析与解答

用一个52位的数组,分别存对应字符串偶数位字母的数量和奇数位字母的数量。

  1. class Solution {
  2. public int numSpecialEquivGroups(String[] words) {
  3. Set<String> seen = new HashSet<>();
  4. for(String S : words) {
  5. int[] count = new int[52];
  6. for(int i = 0;i < S.length();i++) {
  7. count[S.charAt(i) - 'a' + 26 *(i%2)]++;
  8. }
  9. seen.add(Arrays.toString(count));
  10. }
  11. return seen.size();
  12. }
  13. }