
나의 풀이
class Solution {
public int solution(int[][] sizes) {
int answer = 0;
int max_height = 0;
int max_width = 0;
for(int i = 0; i < sizes.length ; i++){
int max = Math.max(sizes[i][0], sizes[i][1]);
int min = Math.min(sizes[i][0], sizes[i][1]);
max_height = Math.max(max_height, max);
max_width = Math.max(max_width, min);
}
return max_height * max_width;
}
}
다른 사람의 풀이
class Solution {
public int solution(int[][] sizes) {
int length = 0, height = 0;
for (int[] card : sizes) {
length = Math.max(length, Math.max(card[0], card[1]));
height = Math.max(height, Math.min(card[0], card[1]));
}
int answer = length * height;
return answer;
}
}
'알고리즘' 카테고리의 다른 글
| [프로그래머스] 숫자 문자열과 영단어(Java) * (0) | 2024.12.02 |
|---|---|
| [프로그래머스] 시저 암호(Java) * (1) | 2024.11.29 |
| [프로그래머스] 크기가 작은 부분 문자열(Java) * (0) | 2024.11.27 |
| [프로그래머스] 삼총사(Java) (0) | 2024.11.26 |
| [프로그래머스] 이상한 문자 만들기(Java) * (0) | 2024.11.25 |