[LeetCode]Palindrome Pairs
摘要:题目:Palindrome Pairs Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two wo
阅读全文
[LeetCode]Shortest Palindrome
摘要:题目:Shortest Palindrome 给定字符串,在前面增加最少字符使其组成回文字符串。 思想: 只要找到从字符串头部开始的最长回文子串,就能将剩下的字符串逆置后拼接到前面而得到最短的回文字符串。 /**判断字符串是回文的**/ bool isPalindrome(string s){ if
阅读全文
[LeetCode]Palindrome
摘要:题目:Palindrome Number 确定一个整数是否是回文。要求没有额外的空间。 思路: 如果有首尾两个指针,则一次比较两个指针对应的数字的值,就能够知道是不是回文数字了; 但是,怎么从后往前遍历呢? 我们可以定义一个数组,分别记录个、十、百、千、万...的位数然后除以数组对应的位数就能从后往
阅读全文
[LeetCode]Longest Palindromic Substring
摘要:题目:Longest Palindromic Substring 查找最长回文子串 思路: 一个指针从头部,一个指针从尾部,对比每一个字母,若相等则可能是回文子串,则,检测子串是否回文,是则比较和已知的子串长度,更长就记录其起始和终止坐标,否则就放弃。 上面的思路是从两边向中间收束,另一个思路是从中
阅读全文