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.
이렇게 풀었어요
1. First Bad Version
1) 복잡도 계산
→ 이진 탐색으로 범위를 절반씩 줄임
→ 추가 자료구조 없음
2) 접근 아이디어
start = 1,end = n으로 설정한다.isBadVersion(mid)가 true이면:end = mid로 줄인다.start = mid + 1로 오른쪽 범위를 탐색한다.start가 첫 bad가 된다.3) 회고
헷갈렸던 포인트는 세 가지였다.
특히
start = middle + 1을 이해하는 게 중요했다.middle이 good이면 정답이 아니므로 해당 값을 버리고 오른쪽으로 이동해야 한다.
2. Ransom Note
1) 복잡도 계산
→ ransomNote, magazine 각각 한 번씩 순회
→ 서로 다른 문자 수만큼 Map 사용
2) 접근 아이디어
ransomNote의 각 문자가 magazine에서 몇 번 필요한지 카운팅 후,
magazine을 순회하면서 해당 문자를 소거하는 방식으로 구현했다.
사고 흐름
3) 다른 사람 풀이 비교
다른 풀이는
indexOf와slice를 이용해magazine에서 문자를 하나씩 찾아 제거하는 방식이었다.
for ransomNote 문자:
magazine에서 해당 문자 index 찾기
없으면 false
있으면 그 문자 제거
4) 회고
이전에는 Map을 두 개 만들어 비교했지만,
이번에는 “소거 방식”으로 하나의 Map만 사용해 구현했다.
indexOf + slice방식은 직관적이지만 큰 입력에서 비효율적일 수 있다.