1002. 查找常用字符
https://leetcode-cn.com/problems/find-common-characters/
解法一:
java
class Solution {
public List<String> commonChars(String[] A) {
int[][] temp = new int[26][A.length];
for (int i = 0; i < A.length; i++) {
for (byte aByte : A[i].getBytes()) {
temp[aByte - 97][i]++;
}
}
List<String> list = new LinkedList<>();
for (int i = 0; i < temp.length; i++) {
int count = 100;
for (int i1 = 0; i1 < A.length; i1++) {
if(temp[i][i1]<count) count = temp[i][i1];
}
for (int j = 0; j < count; j++) {
list.add(Character.toString((char)(i+97)));
}
}
return list;
}
}
最后更新于