We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 515986e commit 502abadCopy full SHA for 502abad
1 file changed
2025-09-03/김대환/프로그래머스_카펫.java
@@ -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