최소직사각형
문제
https://programmers.co.kr/learn/courses/30/lessons/86491
코딩테스트 연습 - 최소직사각형
[[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133
programmers.co.kr
코드
class Solution {
public int solution(int[][] sizes) {
int result = 0;
// 가로를 가장 긴부분으로 설정
int max_w = 0;// 가로
int max_h = 0;// 세로
// Math.min([집합]),Math.max([집합])
for (int i = 0; i < sizes.length; i++) {
int w = Math.max(sizes[i][0], sizes[i][1]);
max_w = Math.max(max_w, w);// 80 출력
int h = Math.min(sizes[i][0], sizes[i][1]);
max_h = Math.max(max_h, h);// 행별 작은 길이를 추출하고 그중 가장 큰값
}
result = max_w * max_h;
return result;
}
}
'프로그래머스 > LEVEL 1' 카테고리의 다른 글
[프로그래머스/LEVEL1] 두 개 뽑아서 더하기 (0) | 2022.01.17 |
---|---|
[프로그래머스/LEVEL1] 같은 숫자는 싫어 (0) | 2022.01.17 |
[프로그래머스/LEVEL1] 3진법 뒤집기 (0) | 2022.01.17 |
[프로그래머스/LEVEL1] 하샤드 수 (0) | 2022.01.17 |
[프로그래머스/LEVEL1] 콜라츠 추측 (0) | 2022.01.17 |