forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1357.java
41 lines (36 loc) · 1.28 KB
/
_1357.java
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
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _1357 {
public static class Solution1 {
public static class Cashier {
int customerCount;
int n;
Map<Integer, Integer> productsToPrices;
int discount;
public Cashier(int n, int discount, int[] products, int[] prices) {
this.n = n;
this.customerCount = 0;
this.discount = discount;
this.productsToPrices = new HashMap<>();
for (int i = 0; i < products.length; i++) {
productsToPrices.put(products[i], prices[i]);
}
}
public double getBill(int[] product, int[] amount) {
double totalPrice = 0;
for (int i = 0; i < product.length; i++) {
totalPrice += productsToPrices.get(product[i]) * amount[i];
}
if (customerCount + 1 == n) {
//apply discount
totalPrice *= (double) (100 - discount) / 100;
customerCount = 0;
} else {
customerCount++;
}
return totalPrice;
}
}
}
}