Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
public class Solution {
public int strStr(String haystack, String needle) {
if (haystack == null) {
return -1;
}
return haystack.indexOf(needle);
}
}
在讨论区看到一个老外在吐槽自己直接用的api竟然还有30%左右的人打败了自己(表示不服)后来有大牛说用indexOf。
卧槽,api宝宝记忆力差