力扣884. 两句话中的不常见单词--python用2行代码实现

思路是使用Counter,将字符串1和字符串2用空格分割。所有=1的就是答案。

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]```

猜你喜欢

转载自blog.csdn.net/weixin_42272768/article/details/127110258