일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Queue
- level4
- mysql
- itertools
- lambda
- join
- BFS
- collections
- coding
- programmers
- 데이터분석
- Stack
- Level2
- counter
- lv4
- sql
- 완전탐색
- 프로그래머스
- 조합
- 파이썬
- coding test
- python
- 코테
- time complexity
- import re
- CodingTest
- 연습문제
- 시간복잡도
- 코딩테스트
- 코딩
- Today
- Total
ror_coding
[Programmers] 콜라 문제 - 132267 본문
728x90
lambda a, b, n : max(n-b, 0) // (a-b)*b 람다 사용 .. 꼭 이해 하자!!
Question
콜라를 받기 위해 마트에 주어야 하는 병 수 a, 빈 병 a개를 가져다 주면 마트가 주는 콜라 병 수 b, 상빈이가 가지고 있는 빈 병의 개수 n이 매개변수로 주어집니다. 상빈이가 받을 수 있는 콜라의 병 수를 return 하도록 solution 함수를 작성해주세요.
Point
- lambda 사용 : Code 1
- while 사용 : Code 2
Code 1 : lambda 사용
solution = lambda a, b, n : max(n-b, 0) // (a-b)*b
Code 2 : my code
def solution(a, b, n):
answer = 0
while n//a > 0 :
answer += (n//a)*b
n = (n//a)*b + n%a
return answer
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/017.gif)
now me
On my github
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmer] 과일 장수 - 135808 (0) | 2024.10.12 |
---|---|
[Programmers] 푸드 파이트 대회 - 134240 (0) | 2024.10.12 |
[Programmers] 2016년 - 12901 (1) | 2024.10.12 |
[Programmers] 문자열 내 마음대로 정렬하기 - 12915 (0) | 2024.10.12 |
[Programmers] 최소직사각형 - 86491 (0) | 2024.10.06 |