判断是否是重复子串

遍历长度,再遍历起点 根据长度 和起点 得到终点(这个地方终点没有使用,类似题目都是这个套路)



public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     * 
     * @param a string字符串 待计算字符串
     * @return int整型
     */
    public int solve (String a) {
        // write code here
        if (a == null|| a == ""|| a.length()==0){
            return  0;
        }
        char[] arrC = a.toCharArray();
        int len = arrC.length;
        int maxLen = 0;
        for (int i = 0; i <=len; i+=2) {
            for (int left = 0; left <= len-i; left++) {
                  int right = left + i-1;
                  if (isMaxString(arrC,left,i)){
                      maxLen = Math.max(maxLen,i);
                  }
            }
        }
        return  maxLen;
    }


    public  boolean isMaxString(char[] arrC,int left,int len){
           int rightEnd = left+len/2;
        for (int i = left; i < rightEnd; i++) {
              int right = i+len/2;
            char leftC = arrC[i];
            char rightC = arrC[right];
            if (leftC != rightC){
                return  false;
            }
        }
        return  true;
    }
}