Skip to content

Commit

Permalink
Time: 38 ms (43.02%) | Memory: 45.7 MB (34.07%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrudhresh committed Nov 1, 2024
1 parent 13a91f3 commit b2894b4
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public String makeFancyString(String s) {
StringBuilder ans = new StringBuilder();
ans.append(s.charAt(0));
int n = s.length(), cnt = 1;
for (int i = 1; i < n; i++) {
if (s.charAt(i) == ans.charAt(ans.length() - 1)) {
cnt++;
if (cnt < 3) {
ans.append(s.charAt(i));
}
} else {
cnt = 1;
ans.append(s.charAt(i));
}
}
return ans.toString();
}
}

0 comments on commit b2894b4

Please sign in to comment.