Re: [閒聊] 每日leetcode

看板Marginalman作者 (dont)時間1年前 (2024/09/02 12:16), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串793/1548 (看更多)
1894. Find the Student that Will Replace the Chalk ## 思路 模擬 每一輪會消耗 sum(chalk) 的粉筆 先取mod 再看最後一輪 ## Code ```python class Solution: def chalkReplacer(self, chalk: List[int], k: int) -> int: n = len(chalk) k = k % sum(chalk) for i in range(n): k -= chalk[i] if k < 0: return i return 0 ``` -- http://i.imgur.com/OLvBn3b.jpg
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 185.213.82.95 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1725250616.A.392.html
文章代碼(AID): #1crJmuEI (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1crJmuEI (Marginalman)