找出最大重复子串(不是最优解)

 @Test
    public void getMaxRepeatSubStr(){
       // for()
    //    contains("badbadx".toCharArray(),"blaaa".toCharArray());
        getMaxSubRepeat("blaaabadbdababad");
    }

    //思想就是:从头开始,你个个截取,然后和余下的字符串比较
    public String getMaxSubRepeat(String str) {
        List list = new ArrayList<>();
        int maxLen = -1;
        if (str == null || str.length() == 0) {
            return null;
        }
        for (int j = 0; j < str.length(); j++) {
            for (int len = (str.length() - j) / 2; len > 0; len--) {
                if(len<=maxLen)
                {
                    break;
                }

                String target = str.substring(j, j+len);
                String remaining = str.substring(j + len);
                if (contains(remaining.toCharArray(), target.toCharArray())) {
                //if (remaining.contains(target)) {
                    maxLen = maxLen

 

你可能感兴趣的:(java)