

-Code
class Solution {
public int[] solution(int brown, int yellow) {
int total = brown + yellow;
for (int h = 3; h <= Math.sqrt(total); h++) {
if (total % h == 0) {
int w = total / h;
if ((w - 2) * (h - 2) == yellow) {
return new int[]{w, h};
}
}
}
return new int[] {0};
}
}
yellow의 경우도 확인해야 하는데 해당 부분을 처음에 빠뜨려서 그걸 고치고 해결했습니다.
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [백준/Java] 1707번 이분 그래프 (0) | 2025.11.19 |
|---|---|
| [백준/Java] 34691번 대전과학고등학교를 사랑하십니까? (0) | 2025.11.19 |
| [프로그래머스/Java] 귤 고르기 (0) | 2025.11.18 |
| [백준/Java] 10426번 기념일 2 (0) | 2025.11.18 |
| [LeetCode/Java] 14. Longest Common Prefix (0) | 2025.11.18 |