IT STUDY LOG

[JAVA] 프로그래머스: 최소직사각형 본문

computer science/coding test

[JAVA] 프로그래머스: 최소직사각형

roheerumi 2023. 5. 4. 09:19

# 문제 내용

[JAVA] 프로그래머스: 최소직사각형

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

# 알고리즘 분류

  • 완전 탐색

 

# 풀이

import java.util.*;

class Solution {
    public int solution(int[][] sizes) {
        int answer = 0;
        int max_w = 0;
        int max_h = 0;
        
        for (int i = 0; i < sizes.length; i++) {
            Arrays.sort(sizes[i]);

            if (max_w < sizes[i][0]) {
                max_w = sizes[i][0];
            }
            if (max_h < sizes[i][1]) {
                max_h = sizes[i][1];
            }
        }
            
        return max_h * max_w;
    }
}

 

Comments