题解NC17 | #最长回文子串#

最长回文子串

https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af

import java.util.*;
import java.util.stream.Collectors;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param A string字符串
     * @return int整型
     */
    public int getLongestPalindrome (String A) {
        int count = 0;
        List<Integer> lengthRecordList = new ArrayList<>();

        boolean[][] check = new boolean[A.length()][A.length()];

        for (int i = A.length() - 1; i >= 0; i--) {
            for (int j = i; j < A.length(); j++) {
                if (A.charAt(i) == A.charAt(j)) {
                    if (j - i < 2) {
                        check[i][j] = true;
                        count++;
                        lengthRecordList.add(j - i + 1);
                    } else if (check[i + 1][j - 1] == true) {
                        check[i][j] = true;
                        count++;
                        lengthRecordList.add(j - i + 1);
                    }
                }
            }
        }

        return  lengthRecordList.stream().sorted(
                    Comparator.reverseOrder()).collect(Collectors.toList()).get(0);
    }
}

一天就做了一题 明天一定要把剩下的做完

全部评论

相关推荐

这算盘打的
程序员小白条:都这样的,都是潜规则,你自己说可以实习一年就行了,实习可以随便跑路的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 13:47
点赞 评论 收藏
分享
一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
废物一个0offer:认真的吗二本本科找人工智能岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 18:05
哈哈哈哈哈感觉朋友找工作的已经疯掉了,直接上图
码农索隆:真老板娘:“我嘞个去,这不我当年的套路吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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