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 32 33 34 35
| class ATM:
def __init__(self): self.banknotes = {} self.a = [20, 50, 100, 200, 500] for i in [20, 50, 100, 200, 500]: self.banknotes[i] = 0
def deposit(self, banknotesCount: List[int]) -> None: for i in range(5): self.banknotes[self.a[i]] += banknotesCount[i]
def withdraw(self, amount: int) -> List[int]: ans = [] tmp = amount for i in range(4, -1, -1): x = min(int(tmp/self.a[i]), self.banknotes[self.a[i]]) ans.append(x) tmp -= x * self.a[i] if tmp != 0: return [-1] ans = ans[::-1] for i in range(5): self.banknotes[self.a[i]] -= ans[i] return ans
|