[Java/Python 3] HashMap/Counter and HashSets.
Method 1:\n1. Count the number of each String in A and B;\n2. Filter out those with occurrence more than 1.\n\n\n    public String[] uncommonFromSentences(Strin
**Method 1:**\n1. Count the number of each String in A and B;\n2. Filter out those with occurrence more than 1.\n\n```\n    public String[] uncommonFromSentences(String A, String B) {\n        Map<String, Integer> count = new HashMap<>();\n        for (String s : (A + " " + B).split("\\\\s")) { \n             count.put(s, count.getOrDefault(s, 0) + 1); \n        }\n        return count.entrySet().stream().filter(e -> e.getValue() == 1).map(e -> e.getKey()).toArray(String[]::new);\n    }\n```\n```python\n    def uncommonFromSentences(self, A: str, B: str) -> List[str]:\n        return [s for s, v in collections.Counter(A.split() + B.split()).items() if v == 1]\n```\n\n----\n\n**Method 2:**\n\nUse 2 HashSets to store distinct and common Strings.\n1. If encounter a String that is not in either Set, add it to distinct;\n2. Otherwise, remove it from the distinct and add it to the common one.\n\nIn other words:\na) first check if the com Set contains the String s, \n          if yes, go to b); \n\t\t\t\t\tif no, check if distinct Set can add s, if yes, no further operation; if no, go to b).\n\nb) remove s from distinct and add it the com Set.\n\n```\n    public String[] uncommonFromSentences(String A, String B) {\n        Set<String> distinct = new HashSet<>(), com = new HashSet<>();\n        for (String s : (A + " " + B).split("\\\\s")) {\n            if (com.contains(s) || !distinct.add(s)) { \n                distinct.remove(s); com.add(s); \n            }\n        }\n        return distinct.toArray(new String[0]);\n    }\n```
[]