https://school.programmers.co.kr/learn/courses/30/lessons/86491
import java.util.Arrays;
class Solution {
public int solution(int[][] sizes) {
int answer = 0;
for (int i=0; i<sizes.length; i++) {
Arrays.sort(sizes[i]);
}
int[] width = new int[sizes.length];
int[] height = new int[sizes.length];
for (int i=0; i<sizes.length; i++) {
width[i] = sizes[i][0]; // 5,3,3,4
height[i] = sizes[i][1]; // 6,7,6,8
}
Arrays.sort(width); //3,3,4,5
Arrays.sort(height); // 6,6,7,8
answer = width[width.length-1] * height[height.length-1];
return answer;
}
}
근데 생각해보니 굳이 정렬 안 해도 Math.max()로 해도 됐겠군....ㅎ.ㅎ 바버....🌟 그래도 맞힌 것에 의의를 ^.^
Math.max(), Math.min() 사용한 풀이 !!
class Solution {
public int solution(int[][] sizes) {
int answer = 0;
int maxWidth = 0; // 지갑의 최대 가로 길이
int maxHeight = 0; // 지갑의 최대 세로 길이
// 각 명함의 크기를 비교하여 최대 가로 및 세로 길이를 결정
for (int[] size : sizes) {
int width = Math.max(size[0], size[1]); // 가로와 세로 중 큰 값
int height = Math.min(size[0], size[1]); // 가로와 세로 중 작은 값
maxWidth = Math.max(maxWidth, width); // 최대 가로 길이 업데이트
maxHeight = Math.max(maxHeight, height); // 최대 세로 길이 업데이트
}
// 지갑의 크기를 계산
answer = maxWidth * maxHeight;
return answer;
}
}