Skip to content

Conversation

Invidam
Copy link
Contributor

@Invidam Invidam commented Jun 8, 2024

문제 해결 후 PR 올립니다!

- 배열의 길이 `n`에 대하여, 범위를 반으로 줄여가며 이분 탐색하므로 `log(n)`이 발생한다.
- 두 이분탐색 함수를 사용하긴 하지만, 합연산이므로 복잡도에는 영향이 없다.
- Space complexity: $O(n), inline$
- 배열의 길이 `n`에 대하여, 입력(`nums`)의 비용이 존재한다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

입력값에 대해서는 고려하지 않아도 되지 않을까 싶네요!

Copy link
Contributor Author

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`)의 비용이 존재한다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 문제도 입력값에 대해서는 고려하지 않아도 될 것 같습니다.

Copy link
Contributor

@bky373 bky373 left a 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 {
Copy link
Contributor

@bky373 bky373 Jun 9, 2024

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 일 때 반복문을 조기 종료시키는 다른 방식보다 연산이 더 길어질 것 같습니다~
현재 코드에서 조기 종료 조건을 추가해보시는 건 어떠신가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생각해보지 못했는데 그것도 좋은 아이디어인 것 같네요!

저도 자세히 아는 건 아니지만, 매번 불필요하게 nums[mid] == target을 검사하는게 더욱 오래걸릴 수도 있다고 들어서 비교를 해봐야 정확히 알 것 같아요!

Copy link
Contributor

@bky373 bky373 Jun 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 갑자기 궁금해져서 gpt 에 질문 올려봤습니다 (재미로 봐주세요 ㅋㅋ)
그냥 선호하시는 스타일 대로(혹은 면접관이 좋아할 만한 스타일 대로?) 작성하시는 게 나을 것 같습니다 ㅋㅋ

nums[mid] == target 동등 비교 검사가 없는 코드(비담님 코드)와 있는 코드(제안드린 코드) 두 개 코드 보여주고 비교해달라 했습니다.

image image

@Invidam Invidam merged commit 0ce8e58 into DaleStudy:main Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants