Skip to content

Commit 502abad

Browse files
committed
20250903 프로그래머스 카펫 문제
1 parent 515986e commit 502abad

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] solution(int brown, int yellow) {
5+
// 정답을 담을 객체
6+
int[] answer = new int[2];
7+
int width;
8+
int height;
9+
10+
// 약수의 조합 찾기
11+
List<List<Integer>> pairs = new ArrayList<>();
12+
13+
for (int i = yellow; i >= 1; i--) {
14+
if (yellow % i == 0) {
15+
int a = i;
16+
int b = yellow/i;
17+
18+
if (a < b) break;
19+
pairs.add(Arrays.asList(a, b));
20+
}
21+
}
22+
23+
for (List<Integer> ele : pairs) {
24+
int c = ele.get(0);
25+
int d = ele.get(1);
26+
int result = 2 * c + 2 * d + 4;
27+
if (result == brown) {
28+
answer[0] = c + 2;
29+
answer[1] = d + 2;
30+
}
31+
}
32+
return answer;
33+
}
34+
}

0 commit comments

Comments
 (0)