-
-
Notifications
You must be signed in to change notification settings - Fork 194
[yyyyyyyyyKim] WEEK 13 solutions #1614
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
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.
설명이 필요한 부분마다 주석이 꼼꼼히 달려 있어 파이썬을 잘 모르는데도 읽는 데 지장이 없었어요.
또 제가 못 푼 문제의 접근 방법을 알아갈 수 있었습니다.
앞으로 2주 남았는데 마지막까지 파이팅하세요~~!
@@ -0,0 +1,27 @@ | |||
class MedianFinder: | |||
# Follow up : 두 개의 heap 사용해서 구현 가능(시간복잡도 O(log n), 추가 공부 필요함) | |||
# heap 사용하지 않고 이진 탐색 삽입으로 풀었음 |
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.
제가 사용하는 자바스크립트에는 힙 같은 자료구조가 내장되어 있지 않아 힙을 직접 구현해야 해서 막막했는데, 이진 탐색 삽입으로 풀이하신 거 보고 저도 이진 탐색으로 풀 수 있었어요..! 감사합니다 👍
# 시간복잡도(O(n^2)), 공간복잡도 O(1) | ||
# 시작점을 기준으로 정렬(선택정렬) | ||
for i in range(len(intervals)): | ||
idx = i | ||
for j in range(i+1,len(intervals)): | ||
if intervals[j].start < intervals[idx].start: | ||
idx = j | ||
if idx != i: | ||
intervals[i], intervals[idx] = intervals[idx], intervals[i] |
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.
내장 함수 sort
를 사용하면 시간복잡도가 O(n log 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.
저는 LintCode에 있는 문제로 풀었는데, LintCode에는 intervals가 리스트가 아닌 클래스 객체라서 sort()로는 정렬이 안 된다고 생각했습니다. 그래서 속성에 직접 접근해서 정렬했습니다!
(람다함수로 key를 지정하면 클래스 객체도 sort()로 정렬할 수 있다는 걸 뒤늦게 깨달았습니다...)
리뷰 감사합니다!
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!