Skip to content

Commit 7aee3c3

Browse files
committed
[PGS] 구명보트 (java) / Level 2 / 10분 / 성공
1 parent ee610f2 commit 7aee3c3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int[] people, int limit) {
5+
int boat = 0;
6+
int left = 0;
7+
int right = people.length - 1;
8+
9+
Arrays.sort(people);
10+
11+
while (left <= right) {
12+
if (people[left] + people[right] <= limit) {
13+
left += 1;
14+
right -= 1;
15+
} else {
16+
right -= 1;
17+
}
18+
boat += 1;
19+
20+
}
21+
return boat;
22+
}
23+
}

0 commit comments

Comments
 (0)