Skip to content

Commit 73050d9

Browse files
committed
Time: 17 ms (80.51%), Space: 45.6 MB (79.79%) - LeetHub
1 parent f3f7983 commit 73050d9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public String compressedString(String word) {
3+
StringBuilder comp = new StringBuilder();
4+
int i = 0;
5+
int n = word.length();
6+
7+
while (i < n) {
8+
char c = word.charAt(i);
9+
int count = 0;
10+
11+
while (i < n && word.charAt(i) == c && count < 9) {
12+
count++;
13+
i++;
14+
}
15+
16+
comp.append(count).append(c);
17+
}
18+
19+
return comp.toString();
20+
21+
}
22+
}

0 commit comments

Comments
 (0)