Lituo884. Uncommon words in two sentences--Python uses 2 lines of code to implement

The idea is to use Counter to separate string 1 and string 2 with spaces. All = 1 is the answer.

class Solution:
    def uncommonFromSentences(self, s1: str, s2: str) -> List[str]:
        c = Counter(s1.split(" ")+s2.split(" "))
        return  [i  for i in c if c[i] ==1]```

Guess you like

Origin blog.csdn.net/weixin_42272768/article/details/127110258