Leetcode 2278. Percentage of Letter in String | | Leetcode 2278. Percentage of Letter in String 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution解析:Version 1,先统计出字符个数,然后求百分比即可。 Version 1 123456789class Solution: def percentageLetter(self, s: str, letter: str) -> int: n = len(s) count = 0 for ch in s: if ch == letter: count += 1 percent = count * 100 // n return percent Reference https://leetcode.com/problems/percentage-of-letter-in-string/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏