inblog logo
|
stupefyee
    알고리즘문제풀기

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

    프로그래머스 (42885)
    Stupefyee's avatar
    Stupefyee
    May 20, 2025
    [JAVA 문제 풀이] 267. 구명보트
    Contents
    내가 작성한 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/42885
    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
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog