Skip to content

Commit 54fd787

Browse files
authored
Merge pull request #1196 from AlgorithmWithGod/0224LJH
[20251022] PGM / Lv2 / 구명보트 / 이종환
2 parents 0f62b91 + 5ab3460 commit 54fd787

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
class Solution {
6+
public int solution(int[] people, int limit) {
7+
8+
Arrays.sort(people);
9+
System.out.println(people);
10+
int front = 0;
11+
int answer = 0;
12+
int back = people.length-1;
13+
14+
while (front < back){
15+
if (people[front]+people[back] <= limit){
16+
answer++;
17+
people[front++] = 0;
18+
people[back--] = 0;
19+
20+
21+
} else{
22+
back--;
23+
}
24+
}
25+
26+
for (int n: people){
27+
if (n != 0) answer++;
28+
}
29+
30+
return answer;
31+
}
32+
}```

0 commit comments

Comments
 (0)