https://school.programmers.co.kr/learn/courses/30/lessons/42885
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
int leftPointer = 0, rightPointer = people.size() - 1;
sort(people.begin(), people.end());
// 투포인터 방식
while (leftPointer <= rightPointer)
{
if (people[leftPointer] + people[rightPointer] <= limit)
++leftPointer;
--rightPointer;
++answer;
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 (0) | 2023.05.31 |
---|---|
[Programmers] (2017 팁스타운) Lv 2. 예상 대진표 (0) | 2023.05.31 |
[Programmers] (완전탐색) Lv 2. 카펫 (0) | 2023.05.25 |
[Programmers] Summer/Winter Coding(~2018) Lv 2. 영어 끝말잇기 (0) | 2023.05.23 |
[Programmers] (2017 팁스타운) Lv 2. 짝지어 제거하기 (0) | 2023.05.23 |
댓글