# 1894. Find the Student that Will Replace the Chalk ###### tags: `Leetcode` `Medium` `Simulation` Link: https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/description/ ## 思路 先求出chalk list的sum 然后k%sum就是最后一轮一共剩了多少chalk 接着遍历chalk array找到要replace chalk的人 ## Code ```python= class Solution: def chalkReplacer(self, chalk: List[int], k: int) -> int: once = sum(chalk) remain = k%once cur = 0 while remain>=chalk[cur]: remain -= chalk[cur] cur+=1 return cur ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up