Merged
Conversation
Mingguriguri
approved these changes
May 18, 2025
Collaborator
There was a problem hiding this comment.
boolean 변수가 아니라 인덱스를 저장하는 변수를 두어서 접근하여, 마지막에 인덱스가 -1이 아닌 경우에만 마크 표시를 하는 것이 인상적이었습니다!
Comment on lines
+49
to
+58
Collaborator
There was a problem hiding this comment.
그리고 입력받은 값을 바로바로 출력하는 것이 아니라 result에 저장해두고, 마지막에 하나씩 출력하는 것도 인상 깊었어요! 참고가 되었습니다 :D
Comment on lines
+67
to
+70
Collaborator
There was a problem hiding this comment.
저는 min()함수를 썼는데 이런 조건식으로 접근할 수도 있는 것, 알아갑니다!
🔥2025-05 챌린지 진행 상황👉 그래프
👉 구현
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🌱WIL
🚀주간 목표 문제 수: 3개
백준 #2110. 공유기 설치: 이분탐색 / 골드 4
정리한 링크: (바로가기)
🚩제출한 코드
💡TIL
풀이 중 발견한 문제점
문제점 1:
while (start < end)조건왜 문제인가?
start < end조건을 사용하면 start가 end와 같아지는 순간 루프가 종료됩니다.그런데 이분 탐색의 핵심은 모든 가능한 거리(mid)에 대해 최적값을 찾는 것입니다.
start == end == mid인 상태에서도 한 번 더 검사를 해야 모든 mid를 확인할 수 있습니다.이 조건으로는 마지막 가능한 거리(mid)를 체크하지 않고 루프가 끝나므로 정답을 놓칠 수 있습니다.
올바른 방법:
while (start <= end)이 조건을 쓰면
start == end일 때도 마지막으로 한 번 더 탐색하고 종료합니다.이는 이분 탐색의 표준 패턴이며, 모든 가능한 값에 대해 판단을 마친 뒤 루프를 종료시킵니다.
문제점 2:
start = mid사용과System.out.println(start - 1)왜 문제인가?
공유기 설치가 가능한 경우
start = mid로 설정하면 mid를 다시 검사하는 상황이 반복될 수 있습니다.예를 들어,
start = 4,end = 5일 때mid = 4가 됩니다.start = mid하면 여전히start = 4,end = 5.mid = 4이고 무한 반복 가능성 발생 → 무한 루프 혹은 탐색 누락올바른 방법:
공유기를 설치할 수 있는 경우는 더 넓은 거리를 확인해야 하므로
start = mid + 1로 가야 합니다.정답 후보는 따로
answer변수에 저장해두고, 탐색 후 출력해야 합니다.백준 #1283. 단축키 지정: 구현 / 실버 1
정리한 링크: (바로가기)
🚩제출한 코드
💡TIL
단축키 저장 자료구로 list대신 set이 더 유리한 이유 정리
이유 1: in 연산의 성능 차이
list는 in 연산시 O(n)소모, set은 in 연산시 O(1)소모
N개의 문장을 처리할 때 단축키 등록 여부를 매번 검사해야 하므로,list보다set이 훨씬 빠르다.이유 2: 의미적으로 중복이 없어야 하는 자료
단축키는 중복되면 안 되기 때문에, 중복을 자동으로 방지하는set이 더 알맞은 자료형이다.백준 #2564. 경비원: 구현 / 실버 1
정리한 링크: (바로가기)
🚩제출한 코드