Implement strStr()

Easy Solved

Description

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.

Input format:

  • Line 1: haystack (string)
  • Line 2: needle (string)

Examples

Input:

hello ll

Output: 2

Input:

aaaaa bba

Output: -1

Input:

abc

Output: 0

Note:

Your program must print a single integer (index) so it can be compared with the expected output.

No submissions yet.

Discuss brute-force string matching vs optimized approaches like KMP.

Test Cases