Skip to content

Commit d9d319a

Browse files
committed
Dec 2
1 parent 31079a3 commit d9d319a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def isPrefixOfWord(self, sentence: str, searchWord: str) -> int:
3+
for idx, word in enumerate(sentence.split(), start=1):
4+
if word.startswith(searchWord):
5+
return idx
6+
return -1
7+
8+
9+
def main():
10+
sentence = 'i love eating burger'
11+
searchWord = 'burg'
12+
assert Solution().isPrefixOfWord(sentence, searchWord) == 4
13+
14+
sentence = 'this problem is an easy problem'
15+
searchWord = 'pro'
16+
assert Solution().isPrefixOfWord(sentence, searchWord) == 2
17+
18+
sentence = 'i am tired'
19+
searchWord = 'you'
20+
assert Solution().isPrefixOfWord(sentence, searchWord) == -1
21+
22+
23+
if __name__ == '__main__':
24+
main()

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
| Day | Problem | Level | Status |
55
| --- | --- | --- | --- |
66
| December 1 | [1346. Check If N and Its Double Exist](https://leetcode.com/problems/check-if-n-and-its-double-exist/) | Easy | Solved |
7-
| December 2 | []() | | |
7+
| December 2 | [1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/) | Easy | Solved |
88
| December 3 | []() | | |
99
| December 4 | []() | | |
1010
| December 5 | []() | | |
@@ -38,6 +38,6 @@
3838
## Summary
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
41-
| Easy | 1 | 1 | 0 |
41+
| Easy | 2 | 2 | 0 |
4242
| Medium | 0 | 0 | 0 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)