[필요개념]
> math.max / math.min 적극활용이 모자랐음
이 쉬운 걸 왜 못 깨달았을까!
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;
}
}
class Solution {
public int solution(int[][] sizes) {
int answer = 0;
int biggersideMax = 0;
int smallersideMax = 0;
for (int[] size : sizes) {
if (size[0] > size[1]) {
if (biggersideMax < size[0]) {
biggersideMax = size[0];
}
if (smallersideMax < size[1]) {
smallersideMax = size[1];
}
} else {
if (biggersideMax < size[1]) {
biggersideMax = size[1];
}
if (smallersideMax < size[0]) {
smallersideMax = size[0];
}
}
}
return answer = biggersideMax * smallersideMax;
}
}
public class Hello {
public static void main(String[] args) {
Solution test = new Solution();
int[][] p = {{60, 50}, {30, 70}, {60, 30}, {80, 40}};
System.out.println(test.solution(p));
}
}
'프로그래머 ,백준, 유튜브, 문제' 카테고리의 다른 글
문자열 내 마음대로 정렬하기_프로그래머스 (1) | 2022.09.26 |
---|---|
로또의 최고 순위와 최저 순위_프로그래머스 (0) | 2022.09.26 |
3진법 뒤집기_프로그래머스 (0) | 2022.09.25 |
하샤드 수_프로그래머스 (1) | 2022.09.25 |
제일 작은 수 제거하기_프로그래머스 (0) | 2022.09.25 |
댓글