[JAVA 문제 풀이] 267. 구명보트

프로그래머스 (42885)
Stupefyee's avatar
May 20, 2025
[JAVA 문제 풀이] 267. 구명보트
notion image
 

내가 작성한 코드

class Solution { public int solution(int[] people, int limit) { int answer = 0; int left = 0; int right = people.length - 1; Arrays.sort(people); // 양 끝에서부터 탐색 // 가장 가벼운 사람과 가장 무거운 사람을 비교하여 // 두 사람을 태울 수 있는지 확인 while (left <= right) { if (people[left] + people[right] <= limit) { left++; } right--; answer++; } return answer; } }
Share article

stupefyee