[robinyoon-dev] WEEK 05 Solutions#2495
Open
robinyoon-dev wants to merge 5 commits intoDaleStudy:mainfrom
Open
Conversation
reeseo3o
approved these changes
Apr 4, 2026
| for (str of strs) { | ||
| let strCountString = getStrCountString(str); | ||
|
|
||
| let hasSameCountIndex = countArr.findIndex((item) => item === strCountString); |
Contributor
There was a problem hiding this comment.
findIndex로 매번 선형 탐색을 해서, 입력 문자열 수가 커지면 시간 복잡도가 많이 커질 것 같아요.
countArr 대신 Map<string, string[]>처럼 strCountString을 key로 바로 그룹 배열을 찾아갈 수 있게 두면, 여기 조회는 평균 O(1)에 처리돼서 전체 성능이 더 좋아질 것 같습니다!
| const Z_ASCII = 'z'.charCodeAt(0); | ||
|
|
||
| let charCounts = Z_ASCII - A_ASCII + 1; | ||
| let charCountArr = new Array(charCounts).fill(0); //인덱스가 알파벳을 나타냄. |
Contributor
There was a problem hiding this comment.
각 문자열을 알파벳 카운트 배열로 바꿔서 비교하는 방식 자체가 정석적인 anagram 풀이 아이디어라서, 접근을 잘 잡으신 것 같아요!
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.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!