标签:
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; }
Java for LeetCode 028 Implement strStr()
标签:
原文地址:http://www.cnblogs.com/tonyluis/p/4474658.html