Coding_Test 연습/Programmers

[프로그래머스] (C++) LV1 최소직사각형

Codetesing 2022. 4. 25. 14:01

W를 명함의 가로, 세로 중 큰 값으로 보고, H를 작은값으로 보고 풀었다.

#include <algorithm>
#include <vector>

using namespace std;

int solution(vector<vector<int>> sizes) {
    int W = 0, H = 0;

    for (int i = 0; i < sizes.size(); i++)
    {
        if (W < max(sizes[i][0], sizes[i][1]))
            W = max(sizes[i][0], sizes[i][1]);
        if (H < min(sizes[i][0], sizes[i][1]))
            H = min(sizes[i][0], sizes[i][1]);
    }

    return W * H;
}