[PGS] 문자열 나누기 - #77
Open
been12151 wants to merge 14 commits into
Open
Conversation
This was
linked to
issues
Jul 14, 2026
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.
🍪 문제 이름
Resolve: 문자열 나누기
🍊 문제 정의
inputs: 영어 소문자로만 이루어진 문자열 (1 ≤ 길이 ≤ 10,000)output예시
🍑 알고리즘 설계
cnt로 기준 글자와의 등장 횟수 차이를 추적.cnt == 0일 때 새 구간이 시작되므로 기준 글자(std)를 갱신하고answer를 1 증가.이후 현재 글자가
std와 같으면cnt를 1 증가, 다르면 1 감소.cnt가 다시 0이 되면 다음 글자에서 새 구간이 시작되는 구조.끝까지
cnt가 0이 되지 않아도 처음 구간 시작 시answer를 이미 올렸기 때문에 별도 처리 없이 자연스럽게 카운트됨.🥝 최악 수행 시간 복잡도
O(n)(n = s의 길이)🍰 특이 사항 (Optional)
구간 시작 시
answer를 먼저 올리는 구조 덕분에 끝까지cnt가 0이 되지 않는 경우(마지막 구간)도 별도 처리 없이 자연스럽게 카운트됨.