Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution(object):
- def uncommonFromSentences(self, s1, s2):
- """
- :type s1: str
- :type s2: str
- :rtype: List[str]
- """
- s1Set = set(s1.split(' '))
- s2Set = set(s2.split(' '))
- s1Set.symmetric_difference_update(s2Set)
- s1Common = self.getComonWords(s1)
- s2Common = self.getComonWords(s2)
- s1Set.difference_update(s1Common)
- s1Set.difference_update(s2Common)
- return s1Set
- def getComonWords(self, sentence):
- uncommon = set()
- common = set()
- for word in sentence.split(' '):
- if word in common:
- continue
- if word in uncommon:
- uncommon.remove(word)
- common.add(word)
- continue
- uncommon.add(word)
- return common
Advertisement
Add Comment
Please, Sign In to add comment