https://school.programmers.co.kr/learn/courses/30/lessons/86491
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 의사 코드
작은 값을 높이로, 큰값을 넓이로 임시저장
기존 maxW, maxH 보다 높은 값일 경우, 해당 값을 저장
마지막으로 두 값을 곱해서 answer로 리턴
2. 제출 코드
#include <string>
#include <vector>
using namespace std;
int solution(vector<vector<int>> sizes) {
int answer = 0;
int maxW = 0;
int maxH = 0;
for ( auto size : sizes)
{
int w = size[0] >= size[1] ? size[0] : size[1];
int h = size[0] >= size[1] ? size[1] : size[0];
if (w > maxW) maxW = w;
if (h > maxH) maxH = h;
}
answer = maxW * maxH;
return answer;
}

반응형
'AlgorithmCodekata' 카테고리의 다른 글
| [AlgorithmCodeKata] 2026-03-20 | 콜라 문제 (0) | 2026.03.20 |
|---|---|
| [AlgorithmCodeKata] 2026-03-18 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.18 |
| [AlgorithmCodeKata] 2026-03-12 | 문자열 내 마음대로 정렬하기 (0) | 2026.03.12 |
| [AlgorithmCodeKata] 2026-03-11 | 숫자 문자열과 영단어 (0) | 2026.03.11 |
| [AlgorithmCodeKata] 2026-03-10 | 시저 암호 (0) | 2026.03.10 |