题目地址:https://leetcode.com/problems/palindrome-partitioning-ii/题目解析:此问题可以使用动态规划,用一个数组保存前i个字符需要的最少cut数,前i+1个字符串的最小cut数为前j个字符所需的cut数(j+1到i个字符为回文)+1;题目解答:...
分类:
其他好文 时间:
2015-04-21 01:40:04
阅读次数:
98
Valid PalindromeTotal Accepted:48909Total Submissions:221328My SubmissionsQuestionSolutionGiven a string, determine if it is a palindrome, considering...
分类:
其他好文 时间:
2015-04-20 23:54:15
阅读次数:
224
经典DP。影响决策的是字符串的内容。而添加和删除字符本质上是一样的,我们不管选择哪一种都可以,所以只需要取两者中费用最小的。
状态转移方程就是:
if(s[i]==s[j]) dp[i][j] = dp[i+1][j-1];
else dp[i][j] = min(dp[i+1][j]+w[s[i]-'a'],dp[i][j-1]+w[s[j]-'a']);
其中dpd...
分类:
其他好文 时间:
2015-04-20 18:32:01
阅读次数:
100
题目:Determine whether an integer is a palindrome. Do this without extra space.
翻译:判断一个数字是否是回文数,不要额外空间。
解题思路:因为数字既然传过去了,就不会有越界的问题。每次只需要取最前面和最后面的那一位数字进行比较,相同则继续,不同则返回、
首先要获取数字的位数,假设数字是12344321,一共有8位。
...
分类:
其他好文 时间:
2015-04-20 17:09:41
阅读次数:
132
思路:前后两个指针。又一次bug free!(但是速度慢。待我想想有什么更好解法么?或者是 判断可以优化?果真!判断isCharEqual(c1,c2)时,可以优化。不需要判断c1到底是大写还是小写)如下面。 bool isCharEqual(char c1, char c2){ ...
分类:
其他好文 时间:
2015-04-19 14:32:58
阅读次数:
111
这道题竟然被我做出来了,不过还是参考别人的,附代码,其中result[i]的意思是从i元素到最后需要的最小切割个数。哈哈class Solution {public: typedef vector> Sdata; int minCut(string s) { int len = s...
分类:
其他好文 时间:
2015-04-18 18:56:50
阅读次数:
121
既然这个是资格赛, 时间也比较充裕, 我就讲解一下我做题的过程
Time Limit:2000ms
Case Time Limit:1000ms
Memory Limit:256MB
Description
Given a string, calculate the number of subsequences that are palindrome. ...
分类:
其他好文 时间:
2015-04-18 13:10:38
阅读次数:
162
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
解题思路:
思路比较简单,将原来的数求逆数。若逆数与原数相等,返回true,否则,返回false。弄清楚,负数能否回文?若溢出咋办?这里总结一下,若遇到整数的逆转,或者字符转化为整数,就需要考虑是否溢...
分类:
其他好文 时间:
2015-04-17 15:42:22
阅读次数:
115
PalindromeTime Limit:3000MSMemory Limit:65536KTotal Submissions:55018Accepted:19024DescriptionA palindrome is a symmetrical string, that is, a string ...
分类:
编程语言 时间:
2015-04-17 10:56:40
阅读次数:
194
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Pana...
分类:
其他好文 时间:
2015-04-16 19:33:20
阅读次数:
110