28. 实现 strStr()
力扣题目链接
class Solution1 {
public int strStr(String haystack, String needle) {
for (int i = 0; i < haystack.length()-needle.length()+1; i++) {
int flag = 0;
for (int j = 0; j < needle.length(); j++) {
if(haystack.charAt(i+j) != needle.charAt(j)){
flag = 1;
break;
}
}
if(flag == 0)
return i;
}
return -1;
}
}
459.重复的子字符串
力扣题目链接
class Solution2 {
public boolean repeatedSubstringPattern(String s) {
String s1 = s;
for (int i = 0; i < s.length()/2; i++) {
String s2 = s1.substring(0,1);
String s3 = s1.substring(1);
s1 = s3+s2;
System.out.println(s1);
if(s1.equals(s))
return true;
}
return false;
}
}