Google – String Appear Only in One List
给k个list of strings, 找出只在一个list里出现的string
Read full article from Google – String Appear Only in One List
给k个list of strings, 找出只在一个list里出现的string
public
List<String> appearOnce(List<List<String>> strings) {
List<String> result =
new
ArrayList<>();
Set<String> set =
new
HashSet<>();
for
(List<String> strs : strings) {
Set<String> local =
new
HashSet<>();
for
(String str : strs) {
local.add(str);
}
for
(String str : local) {
if
(set.contains(str)) {
set.remove(str);//???
}
else
{
set.add(str);
}
}
}
result.addAll(set);
return
result;
}