leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1894.cpp (369B)


0 class Solution {
1 public:
2 int chalkReplacer(const vector<int> &chalk, int k) const {
3 const long long sum = accumulate(begin(chalk), end(chalk), 0ll);
4 int n = 0;
6 k %= sum;
7 while (true) {
8 if (k < chalk[n]) return n;
9 k -= chalk[n];
10 n = (n + 1) % size(chalk);
11 }
13 return -1;
14 }
15 };