-
-
Notifications
You must be signed in to change notification settings - Fork 195
[SunaDu] Week 13 #1073
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
[SunaDu] Week 13 #1073
Conversation
intervals.sort(key=lambda x: x[0]) | ||
|
||
for i in range(1, len(intervals)): | ||
if intervals[i][0] < intervals[i-1][1]: |
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.
맹점이 있다면, 서로 이웃하지 않은 일정들이 겹치는 경우가 있을 수도 있겠네요.
풀이가 깔끔하고 좋습니다.
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.
회의 시작시간 기준으로 오름차순 정렬한 이후
시작시간과 끝나는 시간을 비교하기 때문에
모든 회의를 처리할 수 있습니다🤔
예를 들어 [[1, 5], [6, 7], [4, 10]]인 입력이 있으면
26번째 라인에서 [[1, 5], [4, 10], [6, 7]]로 정렬하기 때문에 겹침을 확인할 수 있어요~
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.
달레님이 더 잘 설명해주신 것 같아 링크 남깁니다🙂
https://www.algodale.com/problems/meeting-rooms/#%ED%92%80%EC%9D%B4-2-%EC%A0%95%EB%A0%AC
class Solution: | ||
def canAttendMeetings(self, intervals: List[List[int]]) -> bool: | ||
intervals.sort(key=lambda x: x[0]) | ||
|
||
for i in range(1, len(intervals)): | ||
if intervals[i][0] < intervals[i-1][1]: |
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.
안녕하세요 @dusunax 님! 저도 같은 방식으로 문제를 풀었는데, 제 코드보다 훨씬 간결해서 참고가 되었습니다 👍
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.
네 감사합니다
@KwonNayeon 님 풀이하고 거의 동일한데 제 풀이는 딱 intervals의 길이만큼 순회하는 구조라서,
배열길이가 0일 시 intervals[0].end에 접근하지 않으니까 키 에러가 나지 않고, 얼리리턴이 필요없었어요.
for interval in intervals[1:]: |
그리고 intervals[1:]은 슬라이싱하면서 새 리스트를 만드니까 인덱스 루프로만 진행하는 것이 성능상의 이점도 있어요!
다만 얼리리턴은 Constraints에서 intervals.length가 0일 수 있다. 라고 했기 때문에 실제 개발에서 나연님처럼 if not intervals: return True
를 명시적으로 표현하는 것도 개발자의 의도를 드러내는 좋은 습관이라고 생각합니다~
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.
와 자세한 설명 감사합니다 🤩 그냥 문제만 풀고 넘어갔으면 이렇게 디테일한 것까지 생각할 기회가 없었을 것 같아요. 선아님이 제 코드와의 다른 점들을 쉽게 설명해주셔서 이해가 쉬웠습니다!
@bus710 @TonyKim9401 |
답안 제출 문제
Week 13
체크 리스트
In Review
로 설정해주세요.