当前位置:网站首页>LeetCode 5. Longest Palindromic Substring
LeetCode 5. Longest Palindromic Substring
2022-07-02 16:40:00 【_ Liu Xiaoyu】
Give you a string s, find s The longest palindrome substring in .
Example 1:
Input :s = “babad”
Output :“bab”
explain :“aba” It's the same answer .
Example 2:
Input :s = “cbbd”
Output :“bb”
Tips :
1 <= s.length <= 1000
s It consists only of numbers and English letters
class Solution {
public:
string longestPalindrome(string s) {
/// There is a horse drawn cart algorithm , We can only do this palindrome substring problem , More biased
// Two points + hash Difficulty upgrade , It can handle millions of levels
// Violence
// Palindrome string It can be divided into odd and even numbers
string re ;
for(int i = 0; i < s.size(); i++)
{
int l = i - 1, r = i + 1;
while(l >= 0 && r < s.size() && s[l] == s[r] ) l --, r ++;
if(re.size() < r - l - 1) re = s.substr(l + 1, r - l - 1); /// l + 1, r - 1
l = i, r= i + 1;
while(l >= 0 && r < s.size() && s[l] == s[r] ) l --, r ++;
if(re.size() < r - l - 1) re = s.substr(l + 1, r - l - 1);
}
return re;
}
};
边栏推荐
- day4
- Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
- Sqlserver queries which indexes are underutilized
- TCP server communication process (important)
- Unity使用UGUI设置一个简单多级水平方向下拉菜单(不需要代码)
- Original God 2.6 server download and installation tutorial
- ROW_ NUMBER()、RANK()、DENSE_ Rank difference
- Set the background picture in the idea (ultra detailed)
- PCL least median square method fitting plane
- Source code look me
猜你喜欢

Practice of traffic recording and playback in vivo

Yyds dry goods inventory # look up at the sky | talk about the way and principle of capturing packets on the mobile terminal and how to prevent mitm

电脑管理员权限在哪里可以打开

自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?

关于mysql安装的一些问题

SSM integration exception handler and project exception handling scheme

Unity uses ugui to set a simple multi-level horizontal drop-down menu (no code required)

PyC file decompile

Foreign enterprise executives, continuous entrepreneurs, yoga and skiing masters, and a program life of continuous iteration and reconstruction

MySQL min() finds the minimum value under certain conditions, and there are multiple results
随机推荐
Analysis of how to prevent virus in industrial computer
学生选课系统(山东农业大学课程设计)
理想之光不灭
What is Amazon keyword index? The consequences of not indexing are serious
大厂面试总结大全
False summer vacation
Original God 2.6 server download and installation tutorial
AWS virtual machine expansion
PCL 点云镜像变换
Leetcode --- longest public prefix
Everyone Xinfu builds: a one-stop intelligent business credit service platform
SSM整合-异常处理器及项目异常处理方案
分析超700万个研发需求发现,这8门编程语言才是行业最需要的!
Yyds dry inventory executor package (parameter processing function)
渗透工具-内网权限维持-Cobalt strike
Yyds dry goods inventory has not revealed the artifact? Valentine's Day is coming. Please send her a special gift~
请问怎么在oracle视图中使用stustr函数
618 reprise en profondeur: la méthode gagnante de la famille Haier Zhi
Download blender on Alibaba cloud image station
Global and Chinese market of switching valves 2022-2028: Research Report on technology, participants, trends, market size and share