Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/08/06 12:34), 編輯推噓1(100)
留言1則, 1人參與, 1年前最新討論串651/1548 (看更多)
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
文章代碼(AID): #1ciQV5SG (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ciQV5SG (Marginalman)