https://programmers.co.kr/learn/courses/30/lessons/42885
그리디 알고리즘
투포인터 알고리즘
투포인터 알고리즘으로 풀었다.
import java.util.*;
class Solution {
public int solution(int[] people, int limit) {
int answer = 0;
Arrays.sort(people);
int lt = 0;
int rt = people.length - 1;
while (lt <= rt) {
if (limit < people[lt] + people[rt]) {
answer++;
rt--;
} else {
answer++;
lt++;
rt--;
}
}
return answer;
}
}