27. Find the Index of the First Occurrence in a String

EasyString

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.

Examples

Input: sadbutsad sad

Output: 0

Explanation: 'sad' occurs first at index 0.

Constraints

  • 1 <= haystack.length, needle.length <= 10^4
  • haystack and needle consist of only lowercase English characters.
Loading...

Run checks all cases above. Submit evaluates all test cases.