voiddeposit(vector<int> banknotesCount){ for (int i = 0; i < 5; i++) { money[i] += banknotesCount[i]; } }
vector<int> withdraw(int amount){ vector<int> ans(5); for (int i = 4; i >= 0 && amount; i--) { ans[i] = min(money[i], amount / per[i]); amount -= ans[i] * per[i]; } if (amount) { return {-1}; } for (int i = 0; i < 5; i++) { money[i] -= ans[i]; } return ans; } };
/** * Your ATM object will be instantiated and called as such: * ATM* obj = new ATM(); * obj->deposit(banknotesCount); * vector<int> param_2 = obj->withdraw(amount); */
publicvoiddeposit(int[] banknotesCount) { for (inti=0; i < 5; i++) { cnt[i] += banknotesCount[i]; } }
publicint[] withdraw(int amount) { int[] ans = newint[5]; for (inti=4; i >= 0; i--) { ans[i] = (int)Math.min(cnt[i], amount / val[i]); amount -= ans[i] * val[i]; } if (amount > 0) { returnnewint[]{-1}; } for (inti=0; i < 5; i++) { cnt[i] -= ans[i]; } return ans; } }
/** * Your ATM object will be instantiated and called as such: * ATM obj = new ATM(); * obj.deposit(banknotesCount); * int[] param_2 = obj.withdraw(amount); */
func(this *ATM) Deposit(banknotesCount []int) { for i := range banknotesCount { this.cnt[i] += (int64)(banknotesCount[i]) } }
func(this *ATM) Withdraw(amount int) []int { ans := make([]int, 5) for i := 4; i >= 0; i-- { ans[i] = (int)(min(this.cnt[i], (int64)(amount) / this.val[i])) amount -= ans[i] * (int)(this.val[i]) } if amount > 0 { return []int{-1} } for i := range this.cnt { this.cnt[i] -= (int64)(ans[i]) } return ans }
/** * Your ATM object will be instantiated and called as such: * obj := Constructor(); * obj.Deposit(banknotesCount); * param_2 := obj.Withdraw(amount); */