题解 | #最长重复子串#

https://www.nowcoder.com/practice/4fe306a84f084c249e4afad5edf889cc

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param a string字符串 待计算字符串
     * @return int整型
     */
    public int solve (String a) {
        // write code here
        int n = a.length();
        int count = 0;
        for(int i = n / 2;i > 0;i--){
            for(int j = 0;j + i < n;j++){
                if(a.charAt(j) == a.charAt(i + j)){
                    count++;
                }else{
                    count = 0;
                }
                if(count == i) return i * 2;
            }
        }
        return 0;
    }
}
全部评论

相关推荐

06-14 19:09
门头沟学院 Java
darius_:给制造业搞的,什么物料管理生产管理,设备管理点检,最最关键的就是一堆报表看板。个人觉得没啥技术含量都是些基本的crud,但是业务很繁琐那种
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务