Leetcode 920 Solution

This article provides solution to leetcode question 920 (uncommon-words-from-two-sentences)

https://leetcode.com/problems/uncommon-words-from-two-sentences

Solution

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