Medium
,Two Pointers
,String
28. Find the Index of the First Occurrence in a String
Given two strings needle
and haystack
, return the index of the first occurrence of needle
in haystack
, or -1
if needle
is not part of haystack
.
Example 1:
Example 2:
Constraints:
haystack.length
, needle.length
<= 104haystack
and needle
consist of only lowercase English characters.Time:
暴力比對也會過,好神秘,還以為一定要寫個KMP什麼的…
MarsgoatMar 3, 2023
https://mp.weixin.qq.com/s/eLtQABruL9-Aut5fXl5x-g
分享一下關於indexOf的底層實作
天宇大神表示 : 88 stupid company