Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string compress(string s) {
- int n = s.size();
- int period = n;
- for (int l = 1; l <= n; l++) {
- bool good = true;
- string need = s.substr(0, l);
- int i = 0;
- while (i < n) {
- string cur = s.substr(i, l);
- for (int j = 0; j < min((int) cur.size(), l); j++) {
- if (cur[j] != need[j]) {
- good = false;
- }
- }
- i += l;
- }
- if (good) {
- period = l;
- break;
- }
- }
- string rep = s.substr(0, period);
- return "(" + rep + ")";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement