leetcode

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

2109.cpp (387B)


      1 class Solution {
      2   public:
      3     string addSpaces(const string &s, const vector<int> &spaces) const {
      4         static char res[600001];
      5         int i = 0, j = 0, k = 0;
      6         while (i < size(s)) {
      7             if (j < size(spaces) && i == spaces[j])
      8                 res[k++] = ' ', j++;
      9             else
     10                 res[k++] = s[i++];
     11         }
     12         return string(res, k);
     13     }
     14 };