Skip to content

Commit 460222f

Browse files
committed
[level 2] Title: 구명보트, Time: 12.13 ms, Memory: 58.4 MB -BaekjoonHub
1 parent 3ba5179 commit 460222f

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

프로그래머스/2/42885. 구명보트/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 10.5 MB, 시간: 9.82 ms
7+
메모리: 58.4 MB, 시간: 12.13 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2024년 2월 2일 0:26:42
19+
2025년 06월 04일 02:22:47
2020

2121
### 문제 설명
2222

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int solution(int[] people, int limit) {
5+
int rideTogether = 0;
6+
7+
Arrays.sort(people);
8+
9+
int left = 0;
10+
int right = people.length - 1;
11+
12+
while(left < right){
13+
if(people[left] + people[right] <= limit){ // 둘이 타기에 충분한 경우
14+
left++;
15+
right--;
16+
rideTogether++;
17+
}else{ // 한명밖에 못타는 경우 -> 무게가 더 많이 나가는 사람을 대체
18+
right--;
19+
}
20+
}
21+
22+
return people.length - rideTogether;
23+
}
24+
}

0 commit comments

Comments
 (0)