给定一个string数组dic,代表单词列表,同时给定列表的长度n,请返回最大子矩阵的面积,其中子矩阵中的行和列相同,且有相同字母组成。保证单词的大小小于等于50,且某一长度的串的数量小于等于12。
测试样例:
["aaa","aaa","aaa","bb","bb"]
返回:9
//能够组成矩阵的必定是单词一样的 public int findAlphaMatrix(String[] dic, int n) { // write code here //利用hashmap统计重复单词数,再从中挑出能组成矩阵的最大值 Map<String, Integer> hash=new HashMap<String, Integer>(); int Max=Integer.MIN_VALUE; for (int i = 0; i < n; i++) { if (hash.containsKey(dic[i])) { hash.put(dic[i], hash.get(dic[i])+1); }else { hash.put(dic[i], 1); } Max=Math.max(Max,dic[i].length()*hash.get(dic[i]) ); } return Max; }