Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
解题思路:
直接看代码即可,JAVA实现如下:
static public int strStr(String haystack, String needle) { for(int i=0;i<=haystack.length()-needle.length();i++) if(haystack.substring(i, i+needle.length()).equals(needle)) return i; return -1; }
时间: 2024-12-20 18:30:07