https://school.programmers.co.kr/learn/courses/30/lessons/86491
가로와 세로 길이를 비교하며 더 큰 수를 가로로 swap
가로 길이 중 제일 큰 수, 세로 길이 중 제일 큰 수 도출 후 곱하여 return
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> sizes)
{
int maxWidth = 0, maxHeight = 0;
for (int i=0; i<sizes.size(); i++)
{
auto info = sizes[i];
if (info[0] < info[1])
swap(info[0], info[1]);
if (maxWidth < info[0])
maxWidth = info[0];
if (maxHeight < info[1])
maxHeight = info[1];
}
return maxWidth * maxHeight;
}
swap을 사용하지 않고 푼 코드
가로 길이 : 짧은 길이 중에 가장 긴 길이 / 세로 길이 : 긴 길이 중에 가장 긴 길이
1에서 구한 가로 * 세로 곱하여 return
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> sizes)
{
int answer=0;
int w=0, h=0;
for(int i=0; i<sizes.size(); i++)
{
w=max(w,min(sizes[i][0],sizes[i][1]));
h=max(h,max(sizes[i][0],sizes[i][1]));
}
answer=w*h;
return answer;
}