Implement strStr()
Easy
Strings
String
Two Pointers
Return the index of first occurrence of needle in haystack, or -1.
Constraints
0 ≤ lengths ≤ 5×10^4
Examples
Example 1:
Input: sadbutsad
sad
Output: 0
Example 2:
Input: leetcode
leeto
Output: -1
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console