Find the Student that Will Replace the Chalk LeetCode solution in Java

1
class Solution {
2

3
public int chalkReplacer(int[] chalk, int k) {
4
long sum = 0;
5
for (int c : chalk) {
6
sum += c;
7
}
8
long left = k % sum;
9
for (int i = 0; i < chalk.length; i++) {
10
if (left >= chalk[i]) {
11
left -= chalk[i];
12
} else {
13
return i;
14
}
15
}
16
return -1; // just for return statement, put whatever you want here
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0