题
思
这题可以加入脑瘫题行列。
代码
class Solution {
public String[] uncommonFromSentences(String A, String B) {
Map<String, Integer> aCount = new HashMap<String, Integer>();
Map<String, Integer> bCount = new HashMap<String, Integer>();
List<String> result = new ArrayList<String>();
for (String s : A.split(" ")) {
aCount.put(s, aCount.getOrDefault(s, 0) + 1);
}
for (String s : B.split(" ")) {
bCount.put(s, bCount.getOrDefault(s, 0) + 1);
}
aCount.keySet().stream().filter(s -> {
return aCount.get(s) == 1 && bCount.get(s) == null;
}).forEach(s -> result.add(s));
bCount.keySet().stream().filter(s -> {
return bCount.get(s) == 1 && aCount.get(s) == null;
}).forEach(s -> result.add(s));
String[] resArray = new String[result.size()];
return result.toArray(resArray);
}
}