leetcode

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

3163.cpp (396B)


      1 class Solution {
      2   public:
      3     string compressedString(const string &word) const {
      4         const int n = size(word);
      5         string res;
      6 
      7         for (int i = 0; i < n;) {
      8             const char c = word[i++];
      9             int cnt = 1;
     10 
     11             while (i < n && cnt < 9 && word[i] == c)
     12                 cnt++, i++;
     13             res += to_string(cnt) + c;
     14         }
     15 
     16         return res;
     17     }
     18 };