Tap here to switch tabs
Problem
Submissions

Problem: Find the Index of the First Occurrence in a String

Find the Index of the First Occurrence in a String asks you to locate where needle first appears within haystack and return its position, or negative one when no match exists.

Statement

Given two strings haystack and needle, return the index of the first occurrence of needle within haystack. If needle does not exist as a substring of haystack, return −1-1.

Constraints:

  • 1≤1 \leq haystack.length, needle.length ≤104\leq 10^4

  • haystack and needle consist of only lowercase English characters

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Index of the First Occurrence in a String

Find the Index of the First Occurrence in a String asks you to locate where needle first appears within haystack and return its position, or negative one when no match exists.

Statement

Given two strings haystack and needle, return the index of the first occurrence of needle within haystack. If needle does not exist as a substring of haystack, return −1-1.

Constraints:

  • 1≤1 \leq haystack.length, needle.length ≤104\leq 10^4

  • haystack and needle consist of only lowercase English characters