Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
Wiki:A Needle in a haystack is a figure of speech used to refer to something that is difficult to locate in a much larger space.
来源于http://blog.youkuaiyun.com/linhuanmars/article/details/20276833
注意总结::
【模型】两个字符串或数组,注意for循环的写法
public class Solution {
public String strStr(String haystack, String needle) {
if(haystack==null || needle==null || needle.length()==0)
return haystack;
if(haystack.length()<needle.length())
return null;
for(int i=0;i<=haystack.length()-needle.length();i++){
boolean successFlag=true;
for(int j=0;j<needle.length();j++){
if(haystack.charAt(i+j)!=needle.charAt(j)){
successFlag=false;
break;
}
}
if(successFlag)
return haystack.substring(i);
}
return null;
}
}