LeetCode - Lemonade Change (Javascript)
문제 설명
줄 서있는 손님들에게 돈을 받은 뒤, 거스름돈을 돌려줄 수 있는지 없는지 판별하는 문제다. (5달러, 10달러, 20달러만 있다고 가정)
At a lemonade stand, each lemonade costs $5
. Customers are standing in a queue to buy from you and order one at a time (in the order specified by bills). Each customer will only buy one lemonade and pay with either a $5
, $10
, or $20
bill. You must provide the correct change to each customer so that the net transaction is that the customer pays $5
.
Note that you do not have any change in hand at first.
Given an integer array bills
where bills[i]
is the bill the ith
customer pays, return true
if you can provide every customer with the correct change, or false
otherwise.
Example 1:
1 | Input: bills = [5,5,5,10,20] |
Example 2:
1 | Input: bills = [5,5,10,10,20] |
Constraints:
1 <= bills.length <= 105
bills[i]
is either5
,10
, or20
.
소스코드
한 번에 성공했다.
시간 효율성도 좋게 나왔는데, 그래도 조금 마음에 걸리는 것은 너무 하드코딩을 했다는 것이다 ㅜ
1 | const lemonadeChange = (bills) => { |
LeetCode - Lemonade Change (Javascript)
https://hoonjoo-park.github.io/algorithm/leet/lemonadeChange/