-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy path1181.py
More file actions
16 lines (16 loc) · 699 Bytes
/
1181.py
File metadata and controls
16 lines (16 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
def beforeAndAfterPuzzles(self, phrases: List[str]) -> List[str]:
res = []
for i in range(len(phrases)):
for j in range(i + 1, len(phrases)):
w1 = phrases[i].split()[-1]
w2 = phrases[j].split()[0]
if w1 == w2:
r = phrases[i] + ' ' + ' '.join(phrases[j].split()[1:])
res.append(r.rstrip())
w1 = phrases[j].split()[-1]
w2 = phrases[i].split()[0]
if w1 == w2:
r = phrases[j] + ' ' + ' '.join(phrases[i].split()[1:])
res.append(r.rstrip())
return sorted(set(res))