-
-
Notifications
You must be signed in to change notification settings - Fork 195
[HoonDongKang] Week 8 solutions #1492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
한 주 동안 문제 푸시느라 정말 고생 많으셨어요! 다음 주도 같이 힘내서 화이팅입니다! 😊
*/ | ||
function characterReplacement(s: string, k: number): number { | ||
//시간복잡도 O(n) | ||
//공간복잡도 O(n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map에는 최대 26개의 알파벳만 key로 들어가므로, 공간 복잡도는 O(1)로 간주할 수 있습니다.
map.set(s[right], (map.get(s[right]) || 0) + 1); | ||
|
||
const maxFreq = Math.max(...Array.from(map.values())); | ||
if (right - left + 1 - maxFreq > k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right 포인터가 한 칸씩만 움직이기 때문에, 조건이 깨질 때 left 포인터도 한 칸씩만 이동해도 충분하다는 점을 이해하게 되었습니다. 저는 이 부분을 while 문으로 처리했었는데, if 문으로 처리해도 결과가 동일하게 나온다는 것을 확인했습니다. 감사합니다! 👍
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!