Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/17684
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
문자열을 압축함.
먼저 모든 영문자가 사전에 있음(1~26)
문자열을 앞에서 한글자씩 보면서 사전에 있는 문자열만큼 봄.
그리고 사전에 있는 문자열 번호를 배열에 저장
그리고 한글자를 더 이어붙인 꼴이 사전에 없다면 추가함.
현재까지 사전에 번호가 26이라면 27에 문자열을 추가
이렇게 문자열 끝까지 진행했을때 출력되는 값들을 배열로 반환.
예를 들어 입력으로 KAKAO가 들어온다고 하자.
현재 사전에는 KAKAO의 첫 글자 K는 등록되어 있으나, 두 번째 글자까지인 KA는 없으므로, 첫 글자 K에 해당하는 색인 번호 11을 출력하고, 다음 글자인 A를 포함한 KA를 사전에 27 번째로 등록한다.
두 번째 글자 A는 사전에 있으나, 세 번째 글자까지인 AK는 사전에 없으므로, A의 색인 번호 1을 출력하고, AK를 사전에 28 번째로 등록한다.
세 번째 글자에서 시작하는 KA가 사전에 있으므로, KA에 해당하는 색인 번호 27을 출력하고, 다음 글자 O를 포함한 KAO를 29 번째로 등록한다.
마지막으로 처리되지 않은 글자 O에 해당하는 색인 번호 15를 출력한다.
🔍 풀이 방법
구현
처음에 아스키코드 변환해서 사전에 영문자들을 저장해둠.
그리고 문제에서 주어지는 방식대로 사전에 있는만큼 문자열을 만들고 출력하고 뒤에 하나 더 붙여서 저장하는 것을 반복
⏳ 회고
그대로 구현하는건데, 사실 StringBuilder를 써서 했었는데 그냥 + 연산이 더 쉬웠다.
그리고 리스트를 배열로 바꾸는 법을 몰라서 찾아봤다.
로직보단 문법에 헷갈렸던 문제