🙄
Устроил двухчасовой мозговой штурм, а им долго, понимаете ли
package com.javarush.task.task08.task0817;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Нам повторы не нужны
*/
public class Solution {
public static Map<String, String> createMap() {
Map<String, String> m = new HashMap<>();
m.put("q", "a");
m.put("w", "s");
m.put("e", "d");
m.put("r", "a");
m.put("t", "f");
m.put("y", "g");
m.put("u", "d");
m.put("i", "k");
m.put("o", "l");
m.put("p", "s");
return m;
}
public static void removeTheFirstNameDuplicates(Map<String, String> map) {
Map<String, String> co = new HashMap<>(map);
ArrayList<String> list = new ArrayList<>();
String x;
for (Map.Entry<String, String> pairs : co.entrySet()) {
String val = pairs.getValue();
list.add(val);
}
for (int i = 0; i < list.size() - 1;) {
x = list.get(i);
for (int j = i + 1; j < list.size() ; j++) {
if (list.get(j) == x) {
i++;
removeItemFromMapByValue(map, x);
}
}
}
}
public static void removeItemFromMapByValue(Map<String, String> map, String value) {
Map<String, String> copy = new HashMap<>(map);
for (Map.Entry<String, String> pair : copy.entrySet()) {
if (pair.getValue().equals(value)) {
map.remove(pair.getKey());
}
}
}
public static void main(String[] args) {
}
}