1
import java.util.HashMap;
public class Main {
public static int minPrice(int[] prices) {
int total = 0;
HashMap<Integer, Integer> uniquePrices = new HashMap<>();
for (int price : prices) {
total += price;
if (uniquePrices.get(price) != null) {
uniquePrices.put(price, uniquePrices.get(price) + price);
} else {
uniquePrices.put(price, price);
}
}
int min = total;
for (Integer value : uniquePrices.values()) {
min = Math.min(min, total - value);
}
return min;
}
public static void main(String[] args) {
int[] prices = {1, 10, 4, 4, 8, 7, 1, 4, 1, 2, 0, 10};
System.out.println(minPrice(prices));
}
}
Comments
Leave a comment