Skip to content

Commit a8ab95c

Browse files
committed
[level 2] Title: 구명보트, Time: 11.06 ms, Memory: 57.6 MB -BaekjoonHub
1 parent bbd14ca commit a8ab95c

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
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-
메모리: 58.4 MB, 시간: 17.38 ms
7+
메모리: 57.6 MB, 시간: 11.06 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 09월 05일 18:27:34
19+
2025년 09월 09일 22:46:20
2020

2121
### 문제 설명
2222

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
class Solution {
44
public int solution(int[] people, int limit) {
5-
ArrayList<Integer> list = new ArrayList<>();
65
Arrays.sort(people);
7-
8-
int light = 0;
9-
int heavy = people.length -1;
106

7+
int light = 0;
8+
int heavy = people.length - 1;
9+
int cnt = 0;
1110
while(light <= heavy){
12-
if(people[light] + people[heavy] > limit){
13-
list.add(people[heavy]);
14-
heavy --;
15-
} else {
16-
list.add(people[heavy] + people[light]);
17-
heavy --;
11+
12+
// 둘이 탈 수 있음
13+
if(people[heavy] + people[light] <= limit){
14+
cnt ++;
15+
heavy --;
1816
light ++;
17+
} else { // 혼자만 탐
18+
cnt ++;
19+
heavy --;
1920
}
2021
}
21-
return list.size();
22+
return cnt;
2223
}
2324
}

0 commit comments

Comments
 (0)