다른사람의 풀이)
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;
}
}
어제 푼 <최소직사각형>을 해결한 다른 사람들의 코드를 리뷰하다가 감탄할만한 코드를 찾았다.
for문이 아닌 Math함수를 통해서 사용할 수 있었을텐데 말이다.
그래서 오늘은 Math함수를 복습하고자 한다.
주요 메소드
Math.abs() | 절대값 반환 |
Math.max() | 최대값 반환 |
Math.min() | 최소값 반환 |
Math.pow() | 제곱 |
Math.sqrt() | 제곱근 |
static double ceil(double a) | 올림 |
static double floor(double a) | 내림 |
나중에는 조금 더 clean하게 풀 수 있도록 해야겠다는 생각이 또 드는 지금이다.
'JAVA' 카테고리의 다른 글
JAVA(2022.09.09) - Stack,Queue를 활용하는 사고 기르기2 (0) | 2022.09.09 |
---|---|
JAVA(2022.09.08) - Stack,Queue를 활용하는 사고 기르기 (0) | 2022.09.08 |
JAVA(2022.08.17)- 사용자 정의 정렬 (0) | 2022.08.17 |
JAVA(2022.08.12)- Comparable, Comparator (0) | 2022.08.12 |
JAVA(2022.08.09) - CollectionFramework (0) | 2022.08.09 |