Skip to content

Commit 55e4120

Browse files
committed
7-6-24
1 parent b0544ba commit 55e4120

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Jun-7-24.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def replaceWords(self, dictionary: List[str], sentence: str) -> str:
3+
res = []
4+
s = set(dictionary)
5+
for i in sentence.split():
6+
for j in range(len(i)):
7+
if i[:j] in s:
8+
res.append(i[:j])
9+
break
10+
if j==len(i)-1 and i[:j] not in s:
11+
res.append(i)
12+
return " ".join(res)

0 commit comments

Comments
 (0)