study/java/src/com/thinker/bishi/offer/CheckSameSubString.java

25 lines
673 B
Java
Raw Normal View History

2020-02-23 14:23:40 +00:00
package com.thinker.bishi.offer;
/**
* @author lzh
* @apiNote 判断一个字符串中是否只含有相同的子字符串子串长度>=2
*/
public class CheckSameSubString {
public static boolean go(String str){
if(null == str || str.length() <= 2) return false;
for(int i=0;i<str.length()-2;i++){
String tmp = str.substring(i,i+2);
int index = str.indexOf(tmp,i+2);
if(index != -1){
return true;
}
}
return false;
}
public static void main(String[] args) {
System.out.println(go("12345623"));
System.out.println(go("adghjkj"));
}
}