bumpsoo 2024-08-06 13:51:01 +09:00
parent 1016645340
commit 501328409d

View file

@ -0,0 +1,19 @@
# https://leetcode.com/problems/minimum-number-of-pushes-to-type-word-ii
from collections import Counter
from functools import reduce
class Solution:
def minimumPushes(self, word: str) -> int:
cnt = Counter(word)
lst = sorted(cnt.values(), reverse=True)
push = 1
ret = 0
for i in range(0, len(lst), 8):
ret += reduce(
lambda x, y: x + y * push,
lst[i:i + 8 if i + 8 < len(lst) else len(lst)],
0
)
push += 1
return ret