Skip to content

Instantly share code, notes, and snippets.

@qrealka
Created May 5, 2020 00:02
Show Gist options
  • Save qrealka/b07ce6f5c5bd82cc25d0379fb2a1c9a9 to your computer and use it in GitHub Desktop.
Save qrealka/b07ce6f5c5bd82cc25d0379fb2a1c9a9 to your computer and use it in GitHub Desktop.
c++ RLE encoding
string compression(const string & str){
int i = str.size();
string letters;
for (int j = 0; j < i; ++j){
int count = 1;
while (str[j] == str[j+1]){
count++;
j++;
}
letters += std::to_string(count);
letters.push_back(str[j]);
}
return letters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment