HTMLify

LeetCode - Uncommon Words from Two Sentences - Python
Views: 22 | Author: abh
class Solution:
    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:
        uncommon_words = []
        s1 = s1.split()
        s2 = s2.split()
        for word in s1:
            if s1.count(word) == 1 and word not in s2:
                uncommon_words.append(word)
        for word in s2:
            if s2.count(word) == 1 and word not in s1:
                uncommon_words.append(word)
        return uncommon_words

Comments