Implement strStr()

Given two strings *haystack* and *needle*, return the index of the first occurrence of *needle* in *haystack*, or -1 if *needle* is not part of *haystack*. If *needle* is an empty string, return 0.

Input Format

First line contains string haystack, second line contains string needle.

Output Format

Output the index of the first occurrence or -1.

Constraints

  • 0 <= len(haystack), len(needle) <= 10^5.

Examples

Example 1:

Input:

haystack = "hello"
needle = "ll"

Output:

2

Example 2:

Input:

haystack = "aaaaa"
needle = "bba"

Output:

-1

Example 3:

Input:

haystack = ""
needle = ""

Output:

0

Example 4:

Input:

haystack = "abc"
needle = "c"

Output:

2
Loading...
Implement strStr() - Strings DSA Problem