Search

[3차] 압축

알고리즘
연습문제
플랫폼
프로그래머스
JCF
LinkedList
상태
해결
생성 일시
2023/12/22 10:47
최종 편집 일시
2023/12/23 05:33

문제 설명

해결과정

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
복사