当前位置:网站首页>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;
}
};
边栏推荐
- Yyds dry inventory KVM new inventory to expand space for home
- Summary of multithreading and thread synchronization knowledge
- LeetCode 4. 寻找两个正序数组的中位数(hard)
- 虚假的暑假
- 大廠面試總結大全
- Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
- Analysis of how to prevent virus in industrial computer
- Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
- 一文读懂AGV的关键技术——激光SLAM与视觉SLAM的区别
- JS learning notes - first acquaintance
猜你喜欢
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
JS learning notes - data types
Headline | Asian control technology products are selected in the textile and clothing industry digital transformation solution key promotion directory of Textile Federation
Summary of monthly report | list of major events of moonbeam in June
请问怎么在oracle视图中使用stustr函数
IDEA中设置背景图片(超详细)
Win11应用商店无法加载页面怎么办?Win11商店无法加载页面
做机器视觉哪个软件好?
路由模式:hash和history模式
Take you ten days to easily complete the go micro service series (I)
随机推荐
Vscade set multi line display of tab
OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
渗透工具-内网权限维持-Cobalt strike
Global and Chinese markets for carbon dioxide laser cutting heads 2022-2028: Research Report on technology, participants, trends, market size and share
Aike AI frontier promotion (2.15)
Trigger: MySQL implements adding or deleting a piece of data in one table and adding another table at the same time
电脑管理员权限在哪里可以打开
Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
Global and Chinese market of oil analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
Original God 2.6 server download and installation tutorial
Download blender on Alibaba cloud image station
OSPF - detailed explanation of NSSA area and full NSSA area (including configuration command), LSA type 7 lsa-7
Mobile web development learning notes - Layout
JS learning notes - operators
Mathematical analysis_ Notes_ Chapter 5: univariate differential calculus
Yyds dry inventory executor package (parameter processing function)
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
unity Hub 登錄框變得很窄 無法登錄
⌈ 2022 ⌋ how to use webp gracefully in projects
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