DOTY
프로그래머스) Lv 1 - 최소직사각형 본문
728x90
반응형
코딩테스트 연습 - 최소직사각형 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <bits/stdc++.h>
using namespace std;
int solution(vector<vector<int>> sizes) {
int answer = 0;
int max_w = 0;
int max_h = 0;
for(int i = 0; i < sizes.size(); i++) {
if(sizes[i][0] < sizes[i][1]) {
int temp = sizes[i][0];
sizes[i][0] = sizes[i][1];
sizes[i][1] = temp;
}
if(max_w < sizes[i][0]) max_w = sizes[i][0];
if(max_h < sizes[i][1]) max_h = sizes[i][1];
}
answer = max_w * max_h;
return answer;
}
헛고생한 문제
감 잡기만 한다면 정말 쉬운 문제..
그냥 명함을 한 방향으로만 넣을수 있다고 생각하고 가로와 세로를 비교해서 가로가 더 짧으면 둘의 길이를 바꿔줬다.
728x90
반응형
'Algorithm > ect' 카테고리의 다른 글
프로그래머스) Lv.1 - 성격 유형 검사하기 (0) | 2023.03.20 |
---|---|
프로그래머스) Lv.3 - 기지국 설치 (0) | 2023.03.18 |
프로그래머스) Lv.2 - 탑 (0) | 2020.10.05 |
프로그래머스) Lv.2 - 주식가격 (0) | 2020.10.05 |
프로그래머스) Lv.2 - 카펫 (0) | 2020.10.05 |
Comments