Skip to content

Commit

Permalink
884
Browse files Browse the repository at this point in the history
Uncommon Words from Two Sentences
  • Loading branch information
rinwf committed Aug 22, 2018
1 parent a0d8b2e commit 565ad54
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lc884.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def uncommonFromSentences(A, B):
"""
:type A: str
:type B: str
:rtype: List[str]
"""
words = A.split() + B.split()
words.sort()
if len(words) < 2:
return words

length = len(words)
i = 0
res = []
while i < length:
if i == length-1:
res.append(words[i])
break
if words[i] == words[i + 1]:
while i < length - 1:
if words[i] == words[i + 1]:
i += 1
else:
break
else:
res.append(words[i])
i += 1
return res


A = "apple apple"
B = "banana"

res = uncommonFromSentences(A, B)

print(res)

0 comments on commit 565ad54

Please sign in to comment.