当前位置:网站首页>每日一题-最长回文子串-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);
}
}
边栏推荐
猜你喜欢

A deep learning code base for Xiaobai, one line of code implements 30+ attention mechanisms.
![[Database and SQL study notes] 9. (T-SQL language) Define variables, advanced queries, process control (conditions, loops, etc.)](/img/7e/566bfa17c5b138d1f909185721c735.png)
[Database and SQL study notes] 9. (T-SQL language) Define variables, advanced queries, process control (conditions, loops, etc.)

5G中切片网络的核心技术FlexE

CVPR2020 - 自校准卷积

GIS面试问题

6k+ star,面向小白的深度学习代码库!一行代码实现所有Attention机制!
![[Intensive reading of the paper] R-CNN's Bounding box regression problem is detailed](/img/ef/a058ec08bd0a6313e3610a4ebc9685.png)
[Intensive reading of the paper] R-CNN's Bounding box regression problem is detailed

【shell编程】第二章:条件测试语句

It turns out that the MAE proposed by He Yuming is still a kind of data enhancement

Redis设计与实现(第一部分):数据结构与对象
随机推荐
【shell编程】第三章:函数
盘点关于发顶会顶刊论文,你需要知道写作上的这些事情!
【UiPath2022+C#】UiPath 练习和解决方案-变量、数据类型和控制流程
亲身实感十多年的面试官面试的题目
Thread handler handle IntentServvice handlerThread
基于STM32F4的FFT+测频率幅值相位差,波形显示,示波器,时域频域分析相关工程
Service
每日一题-字典
CVPR2021 - Inception Convolution with Efficient Dilation Search
(oj)原地移除数组中所有的元素val、删除排序数组中的重复项、合并两个有序数组
【ts】typescript高阶:模版字面量类型
idea 快速日志
IT系统运行维护方法及策略
沁恒MCU从EVT中提取文件建立MounRiver独立工程
吞吐?带宽?傻傻分不清楚
【Promise高级用法】实现并行和串行API
电子产品量产工具(5)- 页面系统实现
栈区中越界可能造成的死循环可能
浅谈遇到的小问题
单变量线性回归