This commit is contained in:
parent
1016645340
commit
501328409d
1 changed files with 19 additions and 0 deletions
19
minimum_number_of_pushes_to_type_word_ii.py
Normal file
19
minimum_number_of_pushes_to_type_word_ii.py
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue