Open
Conversation
sonyerim
reviewed
Nov 12, 2025
There was a problem hiding this comment.
-1 downTo 0 이면 마지막 인덱스부터 처음 인덱스까지 내림차순을 의미하는게 맞을까요?!
Author
There was a problem hiding this comment.
요거 index-1 downTo 0 이라서 해당 인덱스의 앞부터 제일 앞까지에요!!
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.
문제
프로그래머스 - 가장 가까운 같은 글자
문제 설명
문자열 s가 주어졌을 때, s의 각 위치마다 자신보다 앞에 나왔으면서, 자신과 가장 가까운 곳에 있는 같은 글자의 위치
제한 사항
입출력 예시
기본 풀이
입력받은 문자열에 대해서 각 문자에 대해 반복하며 같은 문자의 index를 찾는 문제라고 생각하였습니다.
심화 풀이
위의 코드와 마찬가지로 반복문을 2번 거치기 때문에 O(n^2)의 수행시간을 가짐
이 과정의 경우 위의 2가지 방법과 다르게 미리 인덱스 맵을 준비하고, 맵의 인덱스를 조회하기 때문에 O(n)의 수행시간을 가짐
느낀점
처음에는 정말 단순하게 반복문만 잘 돌리고, 조건문만 잘 설정하면 가볍게 풀 수 있는 문제라고 생각했다.
첫주기도 하고 코틀린으로 알고리즘 문제를 푸는 것이 처음이라 가져오게 되었는데, 그래서 오히려 심화 풀이 부분이 더 신기하고 색다르게 느껴졌다.
어디에나 알고리즘 귀인들은 존재하는 것 같았다.