We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f3f7983 commit 73050d9Copy full SHA for 73050d9
3163-string-compression-iii/3163-string-compression-iii.java
@@ -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