प्रश्न
00:00

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

आसानस्ट्रिंगGoogleMicrosoft

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

उदाहरण 1:

इनपुट: haystack = "sadbutsad", needle = "sad"
आउटपुट: 0

उदाहरण 2:

इनपुट: haystack = "leetcode", needle = "leeto"
आउटपुट: -1

सीमाएँ:

  • 1 <= haystack.length, needle.length <= 10^4
मुख्य कोड मोड
● अपने आप सहेजा गयापंक्ति 1, कॉलम 1