Created
May 5, 2020 00:02
-
-
Save qrealka/b07ce6f5c5bd82cc25d0379fb2a1c9a9 to your computer and use it in GitHub Desktop.
c++ RLE encoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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