Skip to content
LC-0884 Easy LeetCode

884. Uncommon Words from Two Sentences

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 75% Topics: Hash Table, String, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(m + n)
# Space: O(m + n)

import collections

    
class Solution(object):
    def uncommonFromSentences(self, A, B):
        """
        :type A: str
        :type B: str
        :rtype: List[str]
        """
        count = collections.Counter(A.split())
        count += collections.Counter(B.split())
        return [word for word in count if count[word] == 1]

Solution from kamyu104/LeetCode-Solutions · MIT