Conversation
doitchuu
approved these changes
Mar 2, 2026
| * @return {boolean} | ||
| */ | ||
| var canConstruct = function (ransomNote, magazine) { | ||
| if (ransomNote.length > magazine.length) return false; |
| } | ||
|
|
||
| return true; | ||
| }; |
Member
There was a problem hiding this comment.
오 chatCodeAt 메서드가 아직 익숙치 않아서 이렇게 풀 수도 있군용!
알파벳 개수 저장할 배열을 만들어서 배열에 체크하는 것도 좋은 것 같아요! 👍 신박하군용
raejun92
approved these changes
Mar 2, 2026
Collaborator
There was a problem hiding this comment.
저번에는 비슷한 문제를 Map을 활용하셨던 것 같은데 배열도 잘 활용하시는군요!
원하는 것을 자유 자제로 사용하는 모습이 아주 멋집니다!
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.
이렇게 풀었어요
1. First Bad Version
1) 복잡도 계산
시간 복잡도: O(log n)
공간 복잡도: O(1)
2) 접근 아이디어
목표는 첫 번째 Bad 버전의 번호를 찾는 것이다. 범위를 보면 최대 2^31 - 1이다. 이러면 완전탐색으로 순차적으로 찾으면 O(n)으로 최악의 경우 시간초과가 날 것이 분명하다. 이분 탐색으로 매번 mid를 갱신하며 탐색하는 것이 맞을 것 같다.
단계별 사고 과정
mid를 잡는다.
mid가 bad인가?
반복
결과적으로 left가 첫 bad 위치이므로 return
3) 회고
일반 이분탐색처럼 right = mid - 1 했었는데 풀이가 완성되지 않았다. 이 문제는 mid가 bad일 때, mid 자체가 “첫 번째 bad”일 가능성이 있기 때문에 right = mid를 적용해야한다. 그리고 right = mid - 1을 적용하려면 while 루프의 조건문도 left <= right로 변경해야한다.
2. Ransom Note
1) 복잡도 계산
시간 복잡도: O(m + n)
공간 복잡도: O(1)
2) 접근 아이디어
includes로 푸는 문젠줄 알았지만, 알고보니 문자 빈도를 카운트하는 문제였다.
단계별 사고 과정
추가적으로 1 <= ransomNote.length, magazine.length <= 10^5로 ransomNote가 magazine 길이보다 작다는 전제는 없는듯하여 상단에 조기 종료 조건을 추가함
3) 회고
단순히 includes로 판별하려고 했는데, 풀이가 완성되지 않아 문제를 다시 파악해보니
위와 같은 예제가 있을 때, ransomNote에 'a'가 2번 있고, magazine에 'a'가 2번 있어서 true를 반환해야하지만, 단순히 'aba'.includes('aa')로 판단하려고 하면 false를 반환한다는 것이다.
자연스럽게 이 문제는 substring 문제로 접근했는데, 알고보니 문자 빈도를 카운트하는 문제였다.