Notice
Recent Posts
Recent Comments
Link
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

main

[Java] 최소 직사각형 크기 본문

Algorithm

[Java] 최소 직사각형 크기

1984 2022. 9. 13. 18:21

 

class Solution {
    public int solution(int[][] sizes) {
        int answer = 0;
        int max_width = 0;
        int max_height = 0;
        
        int width = 0;
        int height = 0;
        
        for(int i = 0; i < sizes.length; i++){
            if(sizes[i][0] >= sizes[i][1]){
                width = sizes[i][0];
                height = sizes[i][1];
            } else {
                width = sizes[i][1];
                height = sizes[i][0];
            }
            if(max_width < width) max_width = width;
            if(max_height < height) max_height = height;
        }
        answer = max_width * max_height;
        return answer;
    }
}

 

728x90
Comments