
프로그래머스 42885번
https://school.programmers.co.kr/learn/courses/30/lessons/42885?language=java


import java.util.*;
class Solution {
    public int solution(int[] people, int limit) {
        Arrays.sort(people);
        int n = people.length;
        int ans = 0;
        int low = 0;
        int high = n - 1;
        
        while(low <= high) {
            if(people[low] + people[high] <= limit) {
                low++;
            }
            
            high--;
            ans++;
        }
        
        return ans;
    } // End of solution()
} // End of Solution class
import java.util.*;
class Solution {
    private static int N, limit, ans;
    private static int[] people;
    
    public int solution(int[] people, int limit) {
        
        Arrays.sort(people);
        this.people = people;
        N = people.length;
        this.limit = limit;
        ans = 0;
        twoPointer(0, N - 1);
        
        return ans;
    } // End of solution()
    
    public void twoPointer(int low, int high) {
        if(low > high) {
            return;
        }
        
        if(people[low] + people[high] <= limit) {
            twoPointer(low + 1, high - 1);
        } else {
            twoPointer(low, high  - 1);
        }
        
        ans++;
        return;
    } // End of twoPointer()
} // End of Solution class