Longest Palindromic SubstringNov 11 '116971 / 22796
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.
» Solve this problem土方法,N^2
貌似有N的方法:http://leetcode.com/2011/11/longest-palindromic-substring-part-ii.html
class Solution { public: int n; string longestPalindrome(string s) { n = s.size(); int m = 1, l = 0; for (int i = 0; i < n; i++) { int t = 2*maxAt(s, i)+1; if (t > m) { m = t; l = i - t / 2; } } for (int i = 0; i < n - 1; i++) { int t = 2 * maxAt(s, i, i+1); if (t > m) { m = t; l = i - t / 2 + 1; } } return s.substr(l, m); } int maxAt(string s, int k, int kk) { int i = k, j = kk; while (i >= 0 && j < n && s[i] == s[j]) i--, j++; return j - kk; } int maxAt(string s, int k) { int i = k , j = k; while (i >= 0 && j < n && s[i] == s[j]) i--, j++; return j - k - 1; } };
相关推荐
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Java AC 版本
c c语言_leetcode 0005_longest_palindromic_substring.zip
Longest-Palindromic-Substring(最长回文子串) 给定一个字符串 s,找到 s 中最长的回文子串。你可以假设 s 的最大长度为 1000。 Sample 1 输入: "babad" 输出: "bab" 注意: "aba" 也是一个有效答案。 Sample 2 输入...
c语言入门 c语言_leetcode题解05-longest-palindromic-substring.c
java入门 java_leetcode题解之005_Longest_Palindromic_Substring
js js_leetcode题解之5-longest-palindromic-substring.js
* Solution of Longest Palindromic Substring in Java:该题目要求找到最长的回文子串,实现方法使用了动态规划的方法。 * Word Break、Word Break II:该题目要求将字符串分割成单词,实现方法使用了动态规划和...
Palindromic Substring 6.ZigZag Conversion 7.Reverse Integer 8.String To Integer 9.Palindrome Number 10.String To Integer 11.Container With Most Water 12.Integer To Roman 13.Roman To Integer 289 347 ...
最大公共字符串leetcode 最长回文子串 给定一个字符串 s,找出 s 中最长的回文子串。 您可以假设 s 的最大长度为 1000。 Example 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2: ...
leetcode 分类leetcode ...Palindromic Substring 链表 #2:Add Two Numbers 分而治之 #53:Maximum Subarray 队列/集 #3:Longest Substring Without Repeating Characters 优先队列 #23:Merge k Sorted Lists
最大公共字符串leetcode 最长回文子串 给定一个字符串 s,找出 s 中最长的回文子串。 您可以假设 s 的最大长度为 1000。 示例 1: Input: "babad" Output: "bab" Note: "aba" is also a valid answer. 示例 2: ...
longest palindromic substring是一个经典的字符串问题,要求找到字符串中最长的回文子串。可以使用动态规划或Manacher算法来解决该问题。 4. Solution Word Break 单词断词是一个自然语言处理问题,要求将字符串...
Palindromic Substring 7. Reverse Integer 9. Palindrome Number 11. Container With Most Water 12. Integer to Roman 13. Roman to Integer 14. Longest Common Prefix 15. 3Sum 20. Valid Parentheses 21. Merge...
Palindromic Substring 中等 6 ZigZag Conversion 中等 7 Reverse Integer 简单 8 String to Integer (atoi) 中等 9 Palindrome Number 简单 11 Container With Most Water 中等 12 Integer to Roman 中等 13 Roman ...
leetcode双人赛LeetCode 编号 题目 难度 题型 备注 Two Sum 简单 Add Two Numbers 中等 链结串列 重要 Longest Substring Without Repeating Characters 中等 字串 重要 Median of Two Sorted Arrays 困难 数学 ...
Palindromic Substring 006 ZigZag Conversion 007 Reverse Integer 008 String to Integer (atoi) 009 Palindrome Number 010 Regular Expression Matching 011 Container With Most Water 012 Integer to Roman ...
leetcode题库 ...Palindromic Substring 30.1% Medium 0006 ZigZag Conversion 37.5% Medium 0007 Reverse Integer 25.8% Easy 0008 String to Integer (atoi) 15.5% Medium 0009 Palindrome Number 49.4% Easy
Palindromic Substring 最长回文子串 string,dp 8 String to Integer(atoi) 字符串转整数 string 13 Roman to Integer 罗马数字转整数 number,string 14 Longest Common Prefix 最长公共前缀 string 16 3Sum Closest...
LeetCode刷题总结 1.Two Sum 2.Add Two Numbers 3.Longest Substring Without Repeating Characters 4.Median of Two Sorted Arrays 5.Longest Palindromic Substring (Manacher算法待完成) 6.ZigZag Conversion 7....
leetcode信封 ...Palindromic Substring │ RansomNote.java //383. Ransom Note │ RussianDollEnvelope.java //354. Russian Doll Envelopes │ SlidingWindowMaximum.java //239. Sliding Window Maximum