forked from c4fiber/java-onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem2.java
28 lines (20 loc) · 800 Bytes
/
Problem2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package onboarding;
import java.util.regex.Pattern;
public class Problem2 {
// aa, bb, ccc 같은 연속되는 중복 문자
private static final Pattern CONSECUTIVE_DUPLICATE_LETTERS = Pattern.compile("(.)\\1+");
private static final String EMPTY_STRING = "";
public static String solution(String cryptogram) {
return decrypt(cryptogram);
}
private static String decrypt(String cryptogram) {
String result = removeConsecutiveDuplicateLetters(cryptogram);
if (result.equals(cryptogram)) {
return result;
}
return decrypt(result);
}
private static String removeConsecutiveDuplicateLetters(String cryptogram) {
return CONSECUTIVE_DUPLICATE_LETTERS.matcher(cryptogram).replaceAll(EMPTY_STRING);
}
}