leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
3163.cpp (396B)
0 class Solution { 1 public: 2 string compressedString(const string &word) const { 3 const int n = size(word); 4 string res; 5 6 for (int i = 0; i < n;) { 7 const char c = word[i++]; 8 int cnt = 1; 9 10 while (i < n && cnt < 9 && word[i] == c) 11 cnt++, i++; 12 res += to_string(cnt) + c; 13 } 14 15 return res; 16 } 17 };