Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 89e8d2b

Browse files
[211122] 카펫
1 parent 764a586 commit 89e8d2b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
public int[] solution(int brown, int yellow) {
3+
int[] answer = new int[2];
4+
5+
int area = brown + yellow; // 전체 격자 개수
6+
7+
for (int i = 1; i <= area; i++) {
8+
int row = i; // 세로
9+
int col = area / row; // 가로
10+
11+
// 카펫의 가로 길이는 세로 길이와 같거나, 세로 길이보다 길다.
12+
if (row > col)
13+
continue;
14+
15+
if ((row - 2) * (col - 2) == yellow) {
16+
answer[0] = col;
17+
answer[1] = row;
18+
return answer;
19+
}
20+
21+
}
22+
23+
return answer;
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /