Lituo884. 2 つの文で構成される珍しい単語 -- 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