-
-
Notifications
You must be signed in to change notification settings - Fork 244
[SeongA] WEEK 11 Solutions #1930
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.
늦은 리뷰 죄송합니다. 이번 주도 멋지게 풀어 주시느라 수고하셨습니다!
if intervals[i][0] >= currentInterval[0] && intervals[i][0] <= currentInterval[1] { | ||
currentInterval = [currentInterval[0], max(currentInterval[1], intervals[i][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.
if intervals[i][0] >= currentInterval[0] && intervals[i][0] <= currentInterval[1] { | |
currentInterval = [currentInterval[0], max(currentInterval[1], intervals[i][1])] | |
if intervals[i][0] <= currentInterval[1] { | |
currentInterval[1] = intervals[i][1] |
[0]
기준으로 정렬한 상태에서 intervals[i][0] >= currentInterval[0]
은 항상 참일 것 같아요.
왜냐하면 currentInterval = intervals[j]
라고 하면 j <= i
이므로 intervals[i][0] >= intervals[j][0]
가 참이기 때문이에요.
또한 max
연산도 생략 가능해 보입니다.
guard let head = head, head.next != nil, head.next?.next != nil else { | ||
return | ||
} | ||
|
||
var slow = head | ||
var fast = head | ||
|
||
while fast.next != nil && fast.next?.next != nil { | ||
slow = slow.next! | ||
fast = fast.next!.next! | ||
} |
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.
Optional Chaining 대신 이렇게 쓸 수도 있겠네요
guard let head = head, head.next != nil, head.next?.next != nil else { | |
return | |
} | |
var slow = head | |
var fast = head | |
while fast.next != nil && fast.next?.next != nil { | |
slow = slow.next! | |
fast = fast.next!.next! | |
} | |
guard let head = head, let first = head.next, let second = first.next else { | |
return | |
} | |
var slow = head | |
var fast = head | |
while true { | |
guard let first = fast.next, let second = first.next else { | |
break | |
} | |
slow = slow.next! | |
fast = second | |
} |
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!