题目要求:返回haystack中needle的第一次出现的索引,如果needle不是haystack的一部分,则返回-1。
算法设计:使用了Java语言中的contains和indexOf函数
public static int strStr(String haystack, String needle) {
if (haystack.length() < needle.length())
return -1;
if (!haystack.contains(needle))
return -1;
else
return haystack.indexOf(needle);
}