[프로그래머스, 86491] 최소직사각형 (java)
Problem Solving/Programmers

[프로그래머스, 86491] 최소직사각형 (java)

728x90

https://school.programmers.co.kr/learn/courses/30/lessons/86491

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

728x90

메모리: 85.9 MB, 시간: 2.32 ms

사용 알고리즘: 완전탐색

class Solution {
    public int solution(int[][] sizes) {
        
        // 명함의 더 긴 쪽이 무조건 가로로 오게 해서 최대값 구하기
        int x = 0, y = 0;
        int row, column;
        for(int i = 0; i < sizes.length; i++) {
            row = Math.max(sizes[i][0], sizes[i][1]);
            column = Math.min(sizes[i][0], sizes[i][1]);
            
            x = Math.max(x, row);
            y = Math.max(y, column);
        }
        
        int answer =  x * y;
        return answer;
    }
}
728x90