Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- 다익스트라
- 브루트포스
- level0
- 딕셔너리
- BOJ
- python
- level3
- 프로그래머스
- DP
- BFS
- 운영체제
- MYSQL
- 구현
- 코딩테스트
- 스택
- dfs
- 백준
- dict
- level2
- 다이나믹 프로그래밍
- 수학
- 재귀
- N과M
- 그리디
- 가상메모리 관리
- programmers
- level1
- 가상메모리
- 힙
- 파이썬
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [구명보트] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/42885
#프로그래머스 구명보트
def solution(people, limit):
answer = 0
people.sort()
i=0
j=len(people)-1
while i<=j:
if (people[i]+people[j])<=limit:
i+=1
j-=1
answer+=1
return answer
그리디 문제이다.
people을 정렬하고, 뒤에서부터 태우고(j-=1) 무게가 남으면 앞도 태운다(i+=1)
최종적으로 answer을 구한다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [ [3차] 파일명 정렬] 파이썬 (0) | 2021.12.09 |
---|---|
프로그래머스 level2 [1차 캐시] 파이썬 (0) | 2021.12.08 |
프로그래머스 level2 [가장 큰 수] 파이썬 (0) | 2021.12.08 |
프로그래머스 level2 [가장 큰 정사각형 찾기] 파이썬 (0) | 2021.12.08 |
프로그래머스 level2 [2개 이하로 다른 비트] 파이썬 (0) | 2021.12.08 |