Re: [閒聊] 每日leetcode
3016. Minimum Number of Pushes to Type Word II
## 思路
計算每個字出現的次數
再照頻率從最高開始的填
## Complexity
Time: O(N)
Spce: O(26)
## Code
```python
class Solution:
def minimumPushes(self, word: str) -> int:
counter = Counter(word)
ans = 0
for idx, cnt in enumerate(sorted(counter.values(), reverse=True)):
ans += cnt * (1 + idx // 8)
return ans
```
--
http://i.imgur.com/OLvBn3b.jpg

--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.248 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1722918853.A.710.html
推
08/06 12:36,
1年前
, 1F
08/06 12:36, 1F
討論串 (同標題文章)
完整討論串 (本文為第 651 之 1548 篇):