1894. 找到需要补充粉笔的学生编号

题目链接:https://leetcode-cn.com/problems/find-the-student-that-will-replace-the-chalk/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
func chalkReplacer(_ chalk: [Int], _ k: Int) -> Int {
var who = 0, rest = k, n = chalk.count
if n == 1 {
return 0
}
var sum = chalk.reduce(0, +)
var k = k % sum
for i in 0 ..< n {
if chalk[i] > k {
who = i
break
}
k -= chalk[i]
}
return who
}
}

1894. 找到需要补充粉笔的学生编号
https://pisces34.github.io/2021/09/10/leetcode/1894/
发布于
2021年9月10日
许可协议