diff --git a/3163. String Compression III b/3163. String Compression III new file mode 100644 index 0000000..cd104f4 --- /dev/null +++ b/3163. String Compression III @@ -0,0 +1,27 @@ +class Solution { +public: + string compressedString(string word) + { + string ans; + + int count = 0; + char prev = word[0]; + for(auto ch : word) + { + if(prev != ch or count == 9) + { + ans += to_string(count); + ans += prev; + prev = ch; + count = 0; + } + count += 1; + } + if(count) + { + ans += to_string(count); + ans += prev; + } + return ans; + } +};