일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Render Props
- react hook
- hook
- React 공식문서
- Programmers
- codingtest
- React API 참고서
- background tab
- Nextjs
- react
- React18
- Javascript
- background setttimeout
- Nextjs React 18
- Next13
- 고급안내서
- Babel
- notFound()
- getUTCDate
- CSS
- React 18 Nextjs
- React 18
- React 고급 안내서
- context
- react-helmet
- background: url
- React 고급안내서
- RTK Query
- next13 head
- background setInterval
Archives
- Today
- Total
akjfal
[Programmer] [3차] 압축 본문
// 사전 초기화 w 제거 및 w 의 index출력
// 남은글자 w+c를 사전에 등록
import java.util.LinkedList;
import java.util.HashMap;
class Solution {
String[] diction;
HashMap<String, Integer> map = new HashMap<>();
public int[] solution(String msg) {
int[] answer = {};
LinkedList<Integer> list = new LinkedList<>();
char startChar = 'A';
int recentIdx = 0;
for(int i = 0; i < 27; i++){
map.put(Character.toString(startChar+i), ++recentIdx);
}
int start = 0;
int end = 1;
int length = msg.length();
while(start < length){
int lastIdx = 0;
while(start < length){
String test = msg.substring(start, end);
if(map.containsKey(test)){
lastIdx = map.get(test);
end++;
if(end == length+1){
start = length;
list.add(lastIdx);
break;
}
}else{
map.put(test, recentIdx++);
list.add(lastIdx);
start = end-1;
break;
}
}
}
answer = new int[list.size()];
int i = 0;
for(int num : list){
answer[i] = num;
i++;
}
return answer;
}
}
딱히 어려울것없이 흐름대로 풀면된다.
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] 올바른 괄호 (0) | 2021.06.24 |
---|---|
[Programmers] [3차] 파일명 정렬 (0) | 2021.06.24 |
[Programmers] [3차] 방금 그곡 (0) | 2021.06.22 |
[Programmers] 가장 큰 정사각형 찾기 (0) | 2021.06.22 |
[Programmers] 방문 길이 (0) | 2021.06.22 |
Comments