题解:
class Solution {
public:
int chalkReplacer(vector<int>& chalk, int k) {
//先求得一轮次用的总的粉笔数
long long sum = 0;
for(int i = 0;i<chalk.size();i++){
sum+=chalk[i];
}
//求余
k = k%sum;
for(int i = 0;i<chalk.size();i++){
if(k-chalk[i]<0){
//不够分了
return i;
}
//否则 还够分
k -=chalk[i];
}
return -1;
}
};