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)


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