Leetcode Problem 1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence

1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence

Leetcode Solutions

Using split and startswith methods

  1. Split the sentence into words using the split method.
  2. Iterate through the list of words.
  3. For each word, check if it starts with the searchWord using the startswith method.
  4. If a word starts with searchWord, return the 1-indexed position of that word.
  5. If no word is found after iterating through all words, return -1.
UML Thumbnail

Character by Character Comparison

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...