지우너
[프로그래머스] 최소 직사각형 본문
문제
최소직사각형
풀이 및 코드
큰 것 중 최대값과 작은 것 중 최대 값을 찾으면 된다.
문제에서 30x70을 70x30으로 회전해서 수납한다고 했는데, 결국
- 큰값x작은 값의 형태로 만들어 주고
- 큰 값 중 최대값(예제에서는 80), 작은 것 중 최대 값(예제에서는 50)을 구해주면 된다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<vector<int>> sizes) {
int len = sizes.size();
int width = 0, height =0;
for(int i =0; i<len; i++){
int first = max(sizes[i][0], sizes[i][1]);
int second = min(sizes[i][0], sizes[i][1]);
width = max(width, first);
height = max(height, second);
}
return width * height;
}
'Problem Solving' 카테고리의 다른 글
[프로그래머스] 카펫 C++ (0) | 2025.02.21 |
---|---|
[프로그래머스] 모의고사 C++ (0) | 2025.02.19 |
[프로그래머스 SQL 고득점 Kit] GROUP BY (0) | 2025.01.17 |
[프로그래머스 SQL 고득점 Kit] JOIN (0) | 2025.01.14 |
[프로그래머스 SQL 고득점 Kit] SELECT (0) | 2025.01.13 |