[Programmers] - 최소직사각형
문제
쉬운 문제이다.
코드
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> sizes) {
int max_width = 0;
int max_height = 0;
for (int i=0;i < sizes.size();i++){
for (int j = 0; j < 2; j++){
if (sizes[i][0] < sizes[i][1]) {//swap
int temp = 0;
temp = sizes[i][1];
sizes[i][1] = sizes[i][0];
sizes[i][0] = temp;
}
if (max_width < sizes[i][0]) max_width = sizes[i][0];
if (max_height < sizes[i][1]) max_height = sizes[i][1];
}
}
return max_width * max_height;
}
요약
- 처음에 가로세로 중 긴쪽이 많은 곳을 구해 긴쪽으로 몰아 swap을 해주려고했다.
- 그런데 그럴 필요 없이 그냥 긴쪽으로 몰아 넣어 최대값을 구했으면 되는 문제였다.