Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 3163. String Compression III
Original file line number Diff line number Diff line change
@@ -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;
}
};
Loading