No Rules Rules

최소직사각형 (feat. 프로그래머스, 86491번) 본문

생활/코테

최소직사각형 (feat. 프로그래머스, 86491번)

개발하는 완두콩 2022. 8. 17. 22:55
728x90
반응형

최소직사각형
https://school.programmers.co.kr/learn/courses/30/lessons/86491

 

프로그래머스

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

programmers.co.kr

 

반응형

 

// woohyeon.kim
// kim519620.tistory.com
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> sizes) {
    int w = 0, h = 0;
    for(auto i = 0; i < sizes.size(); ++i){
        auto large_value = max(sizes[i][0], sizes[i][1]);
        auto small_value = min(sizes[i][0], sizes[i][1]);
        w = max(w, large_value);
        h = max(h, small_value);
    }
    return w * h;
}
// *&)*@*

 

입력받은 가로/세로 중 큰값 리스트, 작은값 리스트 를 구합니다.

큰값 리스트 중 가장 큰 값과 작은값 리스트 중 가장 큰 값을 서로 곱하여 리턴합니다.

728x90
반응형
Comments