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 Reading material
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
Similar questions