-
Notifications
You must be signed in to change notification settings - Fork 0
[ADD] choyunju 12주차 #43
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
base: main
Are you sure you want to change the base?
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.
수고하셨습니다!!
count += diffDistance[i]/mid; | ||
// 0으로 나누어 떨어진 경우 이미 휴게소가 1개 지어진 경우이므로 -1을 해준다. | ||
if(diffDistance[i] % mid == 0) { | ||
count--; | ||
} |
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.
엇ㅋㅋㅋ 저는 이거를 안될때까지 뺄셈하도록 했는데 나눗셈이라는 똑똑한 방법이...
public static void binary_search(int start, int end) { | ||
while(start < end) { | ||
int diff = arr[start] + arr[end]; | ||
if(min > Math.abs(diff)) { | ||
min = Math.abs(diff); | ||
a = arr[start]; | ||
b = arr[end]; | ||
} | ||
//두 용액의 합이 음수인 경우 | ||
if(diff < 0) { | ||
start++; | ||
} | ||
//두 용액의 합이 양수인 경우 | ||
else if(diff > 0){ | ||
end--; | ||
} | ||
else { | ||
break; | ||
} | ||
} |
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.
아 세상에.. 이렇게하면 이분탐색으로 풀리는군요! 이걸 못떠올려서 절댓값 순으로 정렬해놓고 인접한 값들만 전부 비교했습니다... 😢
} else { | ||
isFlag = true; | ||
break; |
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; 해버리면 플래그를 안써도 깔끔하게 만들수 있습니다 !
✅ 문제번호 | 문제이름 | 난이도: 난이도 | 유형: 유형
📝 문제 설명
💡 풀이 설명