Re: [閒聊] 每日leetcode

作者: dont   2024-09-02 12:16:53
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
```

Links booklink

Contact Us: admin [ a t ] ucptt.com