HTMLify
LeetCode - Apply Discount Every n Orders - Go
Views: 298 | Author: abh
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 36 37 38 39 40 41 42 43 44 45 | type Cashier struct { customers_done int n int discount int products []int prices []int } func Constructor(n int, discount int, products []int, prices []int) Cashier { var cashier Cashier cashier.customers_done = 0 cashier.n = n cashier.discount = discount cashier.products = products cashier.prices = prices return cashier } func (self *Cashier) GetBill(product []int, amount []int) float64 { self.customers_done++ var bill float64 for i:=0; i<len(product); i++ { var price int for _i, _product := range self.products { if _product == product[i] { price = self.prices[_i] break } } bill += float64(price * amount[i]) } if self.customers_done % self.n == 0 { bill *= ((100.0 - float64(self.discount)) / 100.0) } return bill } /** * Your Cashier object will be instantiated and called as such: * obj := Constructor(n, discount, products, prices); * param_1 := obj.GetBill(product,amount); */ |