반응형
    
    
    
  -문제

-코드
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
    int answer = 0,  p1=0, p2=people.size()-1;
    
    sort(people.begin(), people.end());
    while(p1<= p2)
    {
        if (p1== p2)
        {
            answer++;
            break;
        }
        if(people[p1] + people[p2] <= limit )
        {
            answer++;
            p1++;
            p2--;
        }
        else
        {
            answer++;
            p2--;
        }
    }
    return answer;
}반응형
    
    
    
  '이론 > 코딩테스트' 카테고리의 다른 글
| [프로그래머스] level1 포켓몬 (해시맵) (0) | 2022.08.29 | 
|---|---|
| [프로그래머스] level2 피보나치 수 (시간초과 해결) (0) | 2022.08.29 | 
| [백준] 1325번 효율적인 해킹 (DFS) (0) | 2022.08.27 | 
| [백준] 3184번 양 (BFS) (0) | 2022.08.26 | 
| [백준] 1388번 바닥 장식 (BFS) (0) | 2022.08.26 | 
 
                    
                   
                    
                  