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

25 lines
673 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"));
}
}