Link: https://leetcode.com/problems/minimum-number-of-keypresses/description/ ## 思路 将所有字母的出现次数排序 出现次数多的字母肯定要放在每个key的最前面 ## Code ```python= class Solution: def minimumKeypresses(self, s: str) -> int: count = Counter(s) sortedCount = sorted(count.values())[::-1] if len(sortedCount)<=9: return len(s) elif 9<len(sortedCount)<=18: return sum(sortedCount[:9])+2*sum(sortedCount[9:]) else: return sum(sortedCount[:9])+2*sum(sortedCount[9:18])+3*sum(sortedCount[18:]) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up