Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 75f7630

Browse files
Create 220411 구명보트.js 파일 생성 후 1개의 풀이 추가
1 parent 7a81e4f commit 75f7630

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎level-2/구명보트.js‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
//정답 1 - jaewon1676
4+
function solution(people, limit) {
5+
let cnt = 0;
6+
7+
people.sort((a, b) => {return a - b}) // 몸무게 오름차순
8+
9+
while(people.length != 0){ // 무인도에 갖힌 사람이 없어질때까지 반복
10+
if (people[0] + people[people.length-1] <= limit){ // 무게가 되면 둘 다 빼주기
11+
people.pop()
12+
people.shift()
13+
} else {
14+
people.pop() // 무거운사람을 뺴주자
15+
}
16+
cnt++;
17+
}
18+
return cnt;
19+
} // 4주차 2번 문제와 유사함

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /