25 lines
673 B
Java
25 lines
673 B
Java
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"));
|
||
}
|
||
}
|