3541. 找到频率最高的元音和辅音
题目来源:
LeetCode题目:3541. 找到频率最高的元音和辅音 - 力扣(LeetCode)
解题思路:
遍历字符串计数,然后取元音的计数最大值和辅音的计数最大值,返回二者之和即可。
解题代码:
class Solution:def maxFreqSum(self, s: str) -> int:cnt=[0]*26for each in s:cnt[ord(each)-97] += 1maxVovel=0maxConstant=0for i in range(len(cnt)):if i==0 or i==4 or i==8 or i==14 or i==20:maxVovel=max(maxVovel,cnt[i])else:maxConstant=max(maxConstant,cnt[i])return maxConstant+maxVovel
总结:
无官方题解。