Problem Solving
24. Lemonade Change
굥깡
2022. 9. 14. 21:32
728x90
https://leetcode.com/problems/lemonade-change/
Lemonade Change - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
거스름돈을 줄 수 있는지 boolean으로 출력하는 문제
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
d5 = []
d10 = []
for i in bills:
if i == 5:
d5.append(i)
elif i == 10:
d10.append(i)
if len(d5) == 0:
return False
d5.pop()
elif i == 20:
if len(d10) == 0 and len(d5) > 2:
d5.pop()
d5.pop()
d5.pop()
elif len(d10) != 0 and len(d5) != 0:
d5.pop()
d10.pop()
else:
return False
return True
더 효율적인 방법은 없으려나