//str是个只包含小写字母的字符串,以下是统计每个字符出现的频数
int[] cnt = new int[26];
//toCharArray()
for (char ch : str.toCharArray()) {
cnt[ch - 'a']++;
}
//charAt()
for(int i = 0;i<str.length;i++){
char ch = str.charAt(i);
cnt[ch - 'a']++;
}
统计字符串每个字符出现的次数
最新推荐文章于 2023-07-11 15:51:29 发布