Skip to content

Commit 8b241d0

Browse files
authored
Create 3163_string_compression_iii.cpp
1 parent 250914b commit 8b241d0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
string compressedString(string word) {
4+
string comp="";
5+
for(int i=0;i<word.size();){
6+
char ch = word[i];
7+
int cnt = 0;
8+
while(i<word.size()){
9+
if(cnt==9){
10+
break;
11+
}
12+
if(word[i]==ch){
13+
i++;
14+
cnt++;
15+
}
16+
else{
17+
break;
18+
}
19+
}
20+
comp+=to_string(cnt)+ch;
21+
}
22+
return comp;
23+
}
24+
};

0 commit comments

Comments
 (0)