[프로그래머스 Level1] 최소직사각형 (Java11)

안대현·2022년 6월 29일
0

프로그래머스 Level1 : 최소직사각형

Math 함수를 이용하여 무난하게 풀이하였다. 이렇게 프로그래머스에 있는 Level1 문제는 모두 풀이하였고, 앞으로는 Level2 문제와 백준 알고리즘 문제를 풀이할 예정이다.

구현 코드

public class MinRect {
    public int solution(int[][] sizes) {
        int answer;
        int maxWidth = 0, maxHeight = 0;
        int maxNum, minNum;

        for (int[] s : sizes) {
            maxNum = Math.max(s[0], s[1]);
            minNum = Math.min(s[0], s[1]);

            if(maxWidth < maxNum) {
                maxWidth = maxNum;
            }
            if(maxHeight < minNum) {
                maxHeight = minNum;
            }
        }

        answer = maxWidth * maxHeight;

        return answer;
    }
}
profile
백엔드 개발자로 향하는 계단을 오르고 있습니다! 😎

0개의 댓글