- 出現次數最多的字母
給定一個字符串str,現在你需要統計出現次數最多的字母。返回這個字母出現的次數。
樣例
給定str=“ABCabcA”,返回2。
A出現了2次,B出現了1次,C出現了1次,a出現了1次,b出現了1次,c出現了1次,A出現的次數最多,所以返回2。
注意事項
字母中只可能會出現大寫字母或者小寫字母。
字符串長度不超過100000
python3:
class Solution:
"""
@param str: the str
@return: the sum that the letter appears the most
"""
def mostFrequentlyAppearingLetters(self, strr):
# Write your code here.
p = {}
for i in strr:
p[i] = 0
for i in strr:
p[i] += 1
i = 1
for a,b in p.items():
if b > i:
i = b
return i
python中的字典在做這類題的時候還是挺好用的。