找出字符串中出现次数最多的字符。例如:bbcaaa,出现次数最多的字符是a。 c
时间: 2024-05-01 07:17:16 浏览: 79
一个字符串中出现次数最多的字符 统计这个次数【实现代码】
代码如下:
```python
def find_most_frequent_char(s):
char_dict = {}
for char in s:
if char in char_dict:
char_dict[char] += 1
else:
char_dict[char] = 1
max_count = 0
most_freq_char = ''
for char, count in char_dict.items():
if count > max_count:
max_count = count
most_freq_char = char
return most_freq_char
s = 'bbcaaa'
print(find_most_frequent_char(s)) # 输出a
```
阅读全文