-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1357-ApplyDiscountEveryNOrders.cs
52 lines (43 loc) · 1.61 KB
/
1357-ApplyDiscountEveryNOrders.cs
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
46
47
48
49
50
51
52
//-----------------------------------------------------------------------------
// Runtime: 724ms
// Memory Usage: 63.8 MB
// Link: https://leetcode.com/submissions/detail/364017009/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
public class _1357_ApplyDiscountEveryNOrders
{
private readonly IDictionary<int, int> productsPrice;
private readonly int discount;
private readonly int discountCustomer;
private int currentCustomerCount;
public _1357_ApplyDiscountEveryNOrders(int n, int discount, int[] products, int[] prices)
{
this.discount = discount;
this.discountCustomer = n;
this.currentCustomerCount = 0;
productsPrice = new Dictionary<int, int>();
for (int i = 0; i < products.Length; i++)
productsPrice[products[i]] = prices[i];
}
public double GetBill(int[] product, int[] amount)
{
var total = 0.0;
for (int i = 0; i < product.Length; i++)
total += productsPrice[product[i]] * amount[i];
currentCustomerCount++;
if (currentCustomerCount == discountCustomer)
{
currentCustomerCount = 0;
total -= discount / 100.0 * total;
}
return total;
}
}
/**
* Your Cashier object will be instantiated and called as such:
* Cashier obj = new Cashier(n, discount, products, prices);
* double param_1 = obj.GetBill(product,amount);
*/
}