크게 어려운건 없었다.
투포인터 방식을 이용해서 풀었다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
sort(people.begin(), people.end());
int start = 0, end = people.size() - 1;
while (start <= end)
{
if (people[start] + people[end] <= limit)
{
start++;
end--;
answer++;
}
else
{
end--;
answer++;
}
}
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 모음 사전 (0) | 2022.06.03 |
|---|---|
| [프로그래머스] (C++) LV2 전력망을 둘로 나누기 (0) | 2022.06.02 |
| [프로그래머스] (C++) LV2 주식가격 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 영어 끝말잇기 (0) | 2022.06.01 |
| [프로그래머스] (C++) LV2 삼각 달팽이 (0) | 2022.06.01 |