题解:a-z的ASCILL码为97-122,利用ASCILL码解题,将字符的整型ASCILL码作为数组的下标,如该字符出现,则将其下标对应值加1,最后遍历辅助数组,
public boolean checkIfPangram(String sentence) {
int[] chs=new int[256]; //创建辅助数组,下标作为ASCILL码char[] chars = sentence.toCharArray(); //将字符串转化为数组for (int i = 0; i < chars.length; i++) {
//遍历数组int c_int=(int)chars[i]; //将字符转化为ASCILL码chs[c_int]++; //将字符的ASCILL码对应的辅助数组数值累加}for (int i = 97; i <=122 ; i++) {
// a-z的ASCILL码为 97-122if (chs[i]==0) //字符未出现 return false; //返回false}return true; }