Find the Index of the First Occurrence in a String

Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Constraints

  • 1 <= haystack.length, needle.length <= 10^4
  • haystack and needle consist of only lowercase English characters.
Saving… · 3 lines
class Solution:
def findIndexOfFirstOccurrence(self, haystack: str, needle: str) -> int:

Console

Click Run to execute sample tests.