Valid NumberValidate if a given string is numeric.Some examples:"0"=>true" 0.1 "=>true"abc"=>false"1 a"=>false"2e10"=>trueNote:It is intended for the ...
分类:
其他好文 时间:
2014-08-16 01:01:49
阅读次数:
195
题意:给定一个字符串,求最少添加多少个字符可使得该字符串变为回文字符串
分析:设原序列S的逆序列为S' ,最少需要补充的字母数 = 原序列S的长度 - S和S'的最长公共子串长度
原因:要求最少添加几个字符,我们可以先从原串中找到一个最长回文串,然后对于原串中不属于这个回文串的字符,在它关于回文串中心的对称位置添加一个相同字符即可。那么需要添加的字符数量即为n-最长回文串长度。
最长回文串可以看作是原串中前面和后面字符的一种匹配(每个后面的字符在前面找到一个符合位置要求的与它相同的字符)。这种的回文匹配和原...
分类:
其他好文 时间:
2014-08-15 18:02:39
阅读次数:
223
题目大意:
给你m个字符,其中有n种字符,每种字符都有两个值,分别是增加一个这样的字符的代价,删除一个这样的字符的代价,让你求将原先给出的那串字符变成回文串的最小代价。
思路分析:
状态方程:dp[i][j] 表示 区间 i-j是回文串的最小代价。
状态转移:
有三种情况。
1、 i+1 ~ j 已经是回文串了,那么对于 i 这个字符,要么删除掉,要么在这个回文串后面加一个 s...
分类:
其他好文 时间:
2014-08-15 17:55:39
阅读次数:
172
Here another memory for speed implementation:class Solution {public: bool isValidSudoku(vector > &board) { size_t row_cnt = board.size(); ...
分类:
其他好文 时间:
2014-08-15 14:18:48
阅读次数:
194
给定n, 返回所有匹配的n对括号的可能形式. 如给定n= 3, 一个解集是:"((()))", "(()())", "(())()", "()(())", "()()()"本题解法的思路是使用栈seq保存经历的字符串状态;使用栈valid保存对应的字符串中有效的括号对个数;当seq不为空时(即回溯未...
分类:
其他好文 时间:
2014-08-14 19:42:29
阅读次数:
169
Given a string s, partition s such that every substring of the partition is a palindrome.
Return all possible palindrome partitioning of s....
分类:
其他好文 时间:
2014-08-14 16:47:18
阅读次数:
218
本题就是求最长的回文子串。
字符串超长,不过限时却是也很长的15秒,最长的限时之一题目了,如果限时短点的话,估计能过的人不多。
使用Mancher算法是可以秒杀的。
模板式的Manacher算法:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#includ...
分类:
其他好文 时间:
2014-08-14 14:12:18
阅读次数:
139
简单题。#include #include using namespace std;int main() { int T; cin >> T; while (T--) { string s; cin >> s; int l = 0; ...
分类:
其他好文 时间:
2014-08-14 01:22:57
阅读次数:
207
不要因为走的太远而忘记我们为什么出发[问题描述]Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets mu...
分类:
其他好文 时间:
2014-08-14 01:00:57
阅读次数:
160
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...
分类:
其他好文 时间:
2014-08-14 00:59:37
阅读次数:
195