字符串处理
六种鱼
这个作者很懒,什么都没留下…
展开
-
LintCode 生成括号
给定 n 对括号,请写一个函数以将其生成新的括号组合,并返回所有组合结果。 样例 给定 n = 3, 可生成的组合如下:“((()))”, “(()())”, “(())()”, “()(())”, “()()()” 参考资料,感谢Code_Ganker转载 2017-09-08 22:47:14 · 192 阅读 · 0 评论 -
LintCode 最长回文子串
给出一个字符串(假设长度最长为1000),求出它的最长回文子串,你可以假定只有一个满足条件的最长回文串。样例 给出字符串 “abcdzdcab”,它的最长回文子串为 “cdzdc”。挑战 O(n2) 时间复杂度的算法是可以接受的,如果你能用 O(n) 的算法那自然更好。第一次AC的连O(n2)都不是的,是O(n3),遍历所有子串。代码如下:class Solution: """原创 2017-09-11 11:51:20 · 229 阅读 · 0 评论 -
LintCode 电话号码的字母组合
Given a digit string excluded 01, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below.样例 给定 “23”原创 2017-09-09 10:54:52 · 357 阅读 · 0 评论 -
LintCode 恢复IP地址
给一个由数字组成的字符串。求出其可能恢复为的所有IP地址。样例 给出字符串 “25525511135”,所有可能的IP地址为:[ “255.255.11.135”, “255.255.111.35” ]和LintCode 电话号码的字母组合类似。 首先找到合适的位数组合。一共4位,每一位的长度要大于等于1,小于等于3,且4位和为字符串长度. 另外要判断每1 位的数字组合,是否合乎原创 2017-09-11 15:57:44 · 578 阅读 · 0 评论 -
LintCode 最长无重复字符的子串
给定一个字符串,请找出其中无重复字符的最长子字符串。例如,在”abcabcbb”中,其无重复字符的最长子字符串是”abc”,其长度为 3。对于,”bbbbb”,其无重复字符的最长子字符串为”b”,长度为1。从左向右扫描,遇到重复的字符时,从前面出现该字符的位置的下一个字符开始,重新扫描,直到扫描到最后。例如: abcbdefgdk 字符 a b c b d e f原创 2017-09-11 14:25:07 · 259 阅读 · 0 评论 -
LintCode 正则表达式匹配
实现支持’.’和’*’的正则表达式匹配。‘.’匹配任意一个字母。‘*’匹配零个或者多个前面的元素。匹配应该覆盖整个输入字符串,而不仅仅是一部分。需要实现的函数是:bool isMatch(const char *s, const char *p)样例 isMatch(“aa”,”a”) → falseisMatch(“aa”,”aa”) → trueisMatch(“aaa”,”aa”) → fa原创 2017-09-12 15:02:30 · 258 阅读 · 0 评论 -
LintCode 分割字符串
给一个字符串,你可以选择在一个字符或两个相邻字符之后拆分字符串,使字符串由仅一个字符或两个字符组成,输出所有可能的结果给一个字符串”123” 返回[[“1”,”2”,”3”],[“12”,”3”],[“1”,”23”]]递归,和LintCode 电话号码的字母组合类似。 代码如下:public class Solution { /* * @param : a string to原创 2017-10-27 10:21:13 · 481 阅读 · 0 评论 -
LintCode 循环单词
The words are same rotate words if rotate the word to the right by loop, and get another. Count how many different rotate word sets in dictionary.E.g. picture and turepic are same rotate words.注意事项所有单词原创 2017-10-26 21:31:52 · 832 阅读 · 0 评论