Dev
Mentor
Coach Interview AI
Mock Interview AI
Coding Problems
Blog
Pricing
Toggle theme
Sign In
Get Started
Toggle theme
Loading...
For the best coding experience, use a desktop browser.
Easy
String
Implement strStr()
Return the index of the first occurrence of
needle
in
haystack
, or -1.
Examples
Input:
haystack = "sadbutsad", needle = "sad"
Output:
0
Sample Test Cases
Case 1 Input:
"sadbutsad" "sad"
Expected:
0
Case 2 Input:
"leetcode" "leeto"
Expected:
-1
Reset
Run
Submit
Loading editor...
Test Case
Output
Submission
Case 1 Input:
"sadbutsad" "sad"
Expected:
0
Case 2 Input:
"leetcode" "leeto"
Expected:
-1