Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
This question is suppose to be very easy, however, I confuse this question with LeetCode Q3: Longest substring without repeating characters. Thus made many mistakes in the first several tries.
Basically, the simplest solution is brute force one which is similar to code below:
Rount 2.
Use Boyer-Moore algorithm which is easier to understand than KMP and 3-5 times faster than KMP.
No comments:
Post a Comment