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