-
-
Notifications
You must be signed in to change notification settings - Fork 195
[Invidam] Week 06 Solutions #122
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
- 배열의 길이 `n`에 대하여, 범위를 반으로 줄여가며 이분 탐색하므로 `log(n)`이 발생한다. | ||
- 두 이분탐색 함수를 사용하긴 하지만, 합연산이므로 복잡도에는 영향이 없다. | ||
- Space complexity: $O(n), inline$ | ||
- 배열의 길이 `n`에 대하여, 입력(`nums`)의 비용이 존재한다. |
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.
다음부턴 의견 반영해보겠습니다!
- 배열의 길이 `n`에 대하여, 범위를 반으로 줄여가며 이분 탐색하므로 `log(n)`이 발생한다. | ||
|
||
- Space complexity: $O(n), inline$ | ||
- 배열의 길이 `n`에 대하여, 입력(`nums`)의 비용이 존재한다. |
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.
꼼꼼히 작성해주셔서 이해하는 데 큰 도움이 되었습니다 감사합니다!
return hi | ||
} | ||
|
||
func lowerBound(nums []int, target int) int { |
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.
(사소) 사용하신 이분탐색은 결국 lo+1 < hi
조건을 만족할 때만 반복문을 종료할 수 있는데
중간에 nums[mid] == target
일 때 반복문을 조기 종료시키는 다른 방식보다 연산이 더 길어질 것 같습니다~
현재 코드에서 조기 종료 조건을 추가해보시는 건 어떠신가요?
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.
생각해보지 못했는데 그것도 좋은 아이디어인 것 같네요!
저도 자세히 아는 건 아니지만, 매번 불필요하게 nums[mid] == target
을 검사하는게 더욱 오래걸릴 수도 있다고 들어서 비교를 해봐야 정확히 알 것 같아요!
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.
문제 해결 후 PR 올립니다!