문제 설명
해결과정
Solution.java
import java.util.*;
class Solution {
LinkedList<String> dictionary = new LinkedList<>();
LinkedList<Integer> Index = new LinkedList<>();
public int[] solution(String msg) {
initialization();
int start = 0;
int end = 0+1;
String substr = "";
int index = 0;
while(end <= msg.length()) {
substr = msg.substring(start, end);
if(dictionary.contains(substr)) {
index = dictionary.indexOf(substr);
end++;
} else {
Index.addLast(index+1);
dictionary.addLast(substr);
start = end -1;
}
}
Index.addLast(index+1);
int[] answer = new int [Index.size()];
int check = 0;
for(int i : Index) {
answer[check++] = i;
}
return answer;
}
public void initialization() {
int start = (int) 'A';
int end = (int) 'Z';
for(int i = start; i < end+1; i++) {
dictionary.addLast(""+ ((char) i));
}
}
}
Java
복사