Skip to content

Commit

Permalink
프로그래머스/Greedy: 구명보트 (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieunnnn committed Jan 10, 2024
1 parent 037d5db commit dac2e0e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/programmers/algorithmKit/greedy/PROB03.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package programmers.algorithmKit.greedy;

import java.util.*;

public class PROB03 {
public int solution(int[] people, int limit) {
Arrays.sort(people);
int i = 0, j = people.length - 1;
int boats = 0;

while (i <= j) {
if (people[i] + people[j] <= limit) {
i++;
}
j--;
boats++;
}

return boats;
}
}

0 comments on commit dac2e0e

Please sign in to comment.