Soal
00:00

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

MudahStringGoogleMicrosoft

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

Contoh 1:

Input: haystack = "sadbutsad", needle = "sad"
Output: 0

Contoh 2:

Input: haystack = "leetcode", needle = "leeto"
Output: -1

Batasan:

  • 1 <= haystack.length, needle.length <= 10^4
Mode kode inti
● Tersimpan otomatisBaris 1, kolom 1