题意:给定一个字符序列,求最少添加多少个字符能让它变成对称序列
分析:这题的做法竟然是把序列颠倒之后求最长公共子序列,然后n-dp[n][n]就是答案。记住这种做法。
在这里再说一次最长公共子序列的做法:dp[i][j]表示序列1的前i个字符和序列2的前j个字符比较时的最长公共子序列的长度,状态转移公式:1.当a[i]==b[j]时,dp[i][j]=dp[i-1][j-1]...
分类:
其他好文 时间:
2015-06-21 21:11:44
阅读次数:
123
Valid Palindrome : https://leetcode.com/problems/valid-palindrome/Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,
“A man, a pl...
分类:
其他好文 时间:
2015-06-21 18:34:26
阅读次数:
110
Description:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a...
分类:
其他好文 时间:
2015-06-21 17:14:49
阅读次数:
93
题目链接:https://leetcode.com/problems/palindrome-number/
Determine whether an integer is a palindrome. Do this without extra space.
click to show spoilers.
Some hints:
Could negative inte...
分类:
其他好文 时间:
2015-06-21 15:52:27
阅读次数:
145
Determine whether an integer is a palindrome. Do this without extra space.利用余数构造倒置数再判断。var isPalindrome = function(x) { var y = 0 var t = x w...
分类:
其他好文 时间:
2015-06-20 23:30:33
阅读次数:
317
这里,我介绍一下O(n)回文串处理的一种方法。Manacher算法.原文地址:http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub....
分类:
编程语言 时间:
2015-06-20 13:08:23
阅读次数:
192
Description:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, "A man, a plan, ...
分类:
其他好文 时间:
2015-06-19 22:59:13
阅读次数:
165
题目:Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you ca...
分类:
编程语言 时间:
2015-06-18 23:42:31
阅读次数:
198
题意:又是回文判断:该数是否是回文数原题来自:https://leetcode.com/problems/palindrome-number/分析:回文真多,直接把数反转来判断是否相等。 1 class Solution { 2 public: 3 bool isPalindrome(int...
分类:
其他好文 时间:
2015-06-18 21:42:04
阅读次数:
114
题目意思:判断是否为回文数,不许使用额外空间 ps:一直不理解额外空间的意思,int能用吗思路:1.比较头尾 2.翻转,越界问题需考虑 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if(x...
分类:
其他好文 时间:
2015-06-18 19:04:49
阅读次数:
96