알고리즘 풀이/프로그래머스

[level1] 프로그래머스 - 최소직사각형(JAVA)

데롱디롱 2021. 10. 10. 01:10
728x90

 

 

[ 풀이 방법 ]

- 명함의 회전이 가능하므로, 무조건 두 길이 중 긴 것을 같은 방향으로 한다.

- 명함을 넣기 위해서는, 가장 큰 가로 * 가장 큰 세로 만큼의 지갑을 사면 된다.

 

 

가로 60 70 60 80
세로 50 30 30 40

 

 

 

 

[ 전체 코드 ]

class Solution {
    public int solution(int[][] sizes) {
        int big_max = Integer.MIN_VALUE;
        int small_max = Integer.MIN_VALUE;
        
        for(int i = 0; i < sizes.length; i++) {
            big_max = Math.max(big_max, Math.max(sizes[i][0], sizes[i][1]));
            small_max = Math.max(small_max, Math.min(sizes[i][0], sizes[i][1]));
        }

        return big_max * small_max;
    }
}
댓글수0