最长回文子串

中心扩展即可。

public int getLongestPalindrome (String A) {
        // write code here
        int len=A.length();

        int max=1;

        for (int i=0;i<A.length()-1;i++){

            max=Math.max(max,Math.max(func(A,i,i),func(A,i,i+1)));

        }
        return max;
    }

    public int func(String A,int begin,int end){

        while (begin>=0&&end<A.length()&&A.charAt(begin)==A.charAt(end)){
            begin--;
            end++;
        }
        
        return end-begin-1;
    }


全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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