315. 최소직사각형

아현·2021년 10월 10일
0

Algorithm

목록 보기
338/400

프로그래머스




1. 시뮬레이션



def solution(sizes):
    sizes = [sorted(i) for i in sizes] 
    width = [i[0] for i in sizes] 
    height = [i[1] for i in sizes] 
    return max(width) * max(height)





2. JavaScript


function solution(sizes) {
    
    let width = 0, height = 0;
    
    for (let size of sizes){
        width = Math.max(width, Math.max(size[0], size[1]));
        height = Math.max(height, Math.min(size[0], size[1]));
    }
    
    return width * height;
}



3. C++


#include <string>
#include <vector>

using namespace std;

int solution(vector<vector<int>> sizes) {
    int width = 0; 
    int height = 0; 
    for (vector<int> size : sizes) { 
        width = max(width, max(size[0], size[1])); 
        height = max(height, min(size[0], size[1])); 
    } 
    return width * height;



}
profile
For the sake of someone who studies computer science

0개의 댓글