코딩테스트
[프로그래머스][C++] 최소직사각형
이쿠우우
2022. 3. 16. 20:41
반응형
https://programmers.co.kr/learn/courses/30/lessons/86491
코딩테스트 연습 - 최소직사각형
[[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133
programmers.co.kr
글쓴이의 답
개인적인 풀이 임으로
이것보다 더 좋은 알고리즘은 많음...
이렇게도 풀이하는구나.. 공유하기 위해 올림...
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int solution(vector<vector<int>> sizes) {
int answer = 0;
int w=0;
int h=0;
for(vector<int> temp : sizes){
int a;
int b;
if (temp[0] > temp[1]){
a = temp[0];
b = temp[1];
}
else {
b = temp[0];
a = temp[1];
}
if(w < a){
w = a;
}
if(h < b){
h = b;
}
}
answer = w*h;
return answer;
}
꾸준히 하다보면 실력이 늘겠지..
반응형