Skip to content

Commit b85830e

Browse files
authored
Create Delete Characters to Make Fancy String.java
1 parent f2b9fe1 commit b85830e

File tree

1 file changed

+18
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)