当前位置:网站首页>每日一题-最长回文子串-0714
每日一题-最长回文子串-0714
2022-08-05 05:17:00 【菜鸡程序媛】
题目:
给你一个字符串 s,找到 s 中最长的回文子串。
解题思路:
代码:
class Solution {
public String longestPalindrome(String s) {
if(s == null || s.length() == 0)
return null;
String reverse = new StringBuilder(s).reverse().toString();
int[] arr = new int[s.length()];
int maxLen = 0;
int endX = 0;
for(int i = 0; i < s.length(); i ++){
for(int j = reverse.length() - 1; j >=0; j --){
if(s.charAt(i) == reverse.charAt(j)){
if(j == 0)
arr[j] = 1;
else
arr[j] = arr[j - 1] + 1;
}else
arr[j] = 0;
if(maxLen < arr[j]){
int before = s.length() - 1 - j;
if(before + arr[j] - 1 == i){
maxLen = arr[j];
endX = i;
}
}
}
}
return s.substring(endX - maxLen + 1, endX + 1);
}
}
边栏推荐
猜你喜欢

【UiPath2022+C#】UiPath 练习和解决方案-变量、数据类型和控制流程

读论文- pix2pix

The University of Göttingen proposed CLIPSeg, a model that can perform three segmentation tasks at the same time

用GAN的方法来进行图片匹配!休斯顿大学提出用于文本图像匹配的对抗表示学习,消除模态差异!

Thread handler handle IntentServvice handlerThread

伪RTOS-ProroThread在CH573芯片上的移植

Machine Learning (1) - Machine Learning Fundamentals
![[Pytorch study notes] 11. Take a subset of the Dataset and shuffle the order of the Dataset (using Subset, random_split)](/img/59/ce3e18f32c40a97631f5ac1b53662a.png)
[Pytorch study notes] 11. Take a subset of the Dataset and shuffle the order of the Dataset (using Subset, random_split)

手把手教你搭建小程序

leetCode刷题之第31题
随机推荐
【UiPath2022+C#】UiPath控制流程概述
tensorflow的session和内存溢出
[Pytorch study notes] 10. How to quickly create your own Dataset dataset object (inherit the Dataset class and override the corresponding method)
基于STM32F407的一个温度传感器报警系统(用的是DS18B20温度传感器,4针0.96寸OLED显示屏,并且附带日期显示)
读论文-Cycle GAN
【shell编程】第三章:函数
基于STM32F4的FFT+测频率幅值相位差,波形显示,示波器,时域频域分析相关工程
UiPath简介
原型版本管理
C语言的一些小常识
【UiPath2022+C#】UiPath Switch
「实用」运维新手一定不能错过的17 个技巧
C语言—扫雷的实现
【22李宏毅机器学习】课程大纲概述
It turns out that the MAE proposed by He Yuming is still a kind of data enhancement
Machine Learning (1) - Machine Learning Fundamentals
idea 快速日志
深度学习系列(二)优化器 (Optimization)
C语言入门笔记 —— 初识
电子产品量产工具(5)- 页面系统实现