
字符串
_IanXiao
这个作者很懒,什么都没留下…
展开
-
LeetCode12. Integer to Roman
题目链接: https://leetcode.com/problems/integer-to-roman/题目描述:将一个整数转化成罗马数字字符串。题目分析:【罗马数字】1~9: {“I”, “II”, “III”, “IV”, “V”, “VI”, “VII”, “VIII”, “IX”};10~90: {“X”, “XX”, “XXX”, “XL”, “L”, “LX”, “LXX”, “原创 2016-01-17 16:04:29 · 416 阅读 · 0 评论 -
LeetCode205. Isomorphic Strings
题目链接: https://leetcode.com/problems/isomorphic-strings/题目描述:判断两个字符串s,t是否同构。 s中的字符能被t中对应字符替换。For example, Given “egg”, “add”, return true.Given “foo”, “bar”, return false.Given “paper”, “title”, re原创 2016-01-24 12:51:00 · 399 阅读 · 0 评论 -
PAT1077 Kuchiguse (20)
题目链接: http://www.nowcoder.com/pat/5/problem/4307题目描述:求字符串的最长公共后缀。题目分析:跟LeetCode上有道求字符串组的最长公共前缀没啥区别啊,就是反起来从后往前遍历。一边比较一边记录当前最长公共后缀的长度,下一个字符串与当前字符串比较得出来的最长公共后缀长度只可能比当前小或者等于。代码:#include<iostream>#inclu原创 2016-01-24 20:19:47 · 709 阅读 · 0 评论 -
LeetCode299. Bulls and Cows
题目链接: https://leetcode.com/problems/bulls-and-cows/题目描述:猜数字游戏,两个字符串,secret与 guess,将guess与secret比较,找出guess中,有多少是数字正确且位置正确的,有多少是数字正确位置错误的。Secret number: “1807” Friend’s guess: “7810” return “1A3B”S原创 2016-01-25 21:09:02 · 433 阅读 · 0 评论 -
LeetCode6. ZigZag Conversion
题目链接: https://leetcode.com/problems/zigzag-conversion/题目描述将字符串,循环对角化,在输出。比如: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20循环对角化成之字型。0 8 16 1原创 2016-01-12 21:54:59 · 517 阅读 · 0 评论 -
LeetCode131. Palindrome Partitioning
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = “aab”,Return[ ["aa","b"], ["a原创 2016-02-11 20:42:30 · 544 阅读 · 0 评论 -
LeetCode8. String to Integer (atoi)
题目链接: https://leetcode.com/problems/string-to-integer-atoi/题目描述:将字符串转化为int型整数。题目分析:题不难,细节太多。需要注意的是:在未处理数字字符前,数字前有空格的跳过,例如s=” 123” result=123;字符串中有‘+’,‘-’号,需要表示int型结果的正负,例如s=”-123” result=123;字符串原创 2016-01-13 12:02:43 · 417 阅读 · 0 评论 -
LeetCode67. Add Binary
题目链接: https://leetcode.com/problems/add-binary/题目描述:将二进制字符串相加。题目分析:嗯,需要注意的就是C++中数字转换字符串的方法。string numToStr(int i){ stringstream ss; ss<<i; return ss.str();}代码:class Solutio原创 2016-01-13 14:15:06 · 446 阅读 · 0 评论 -
LeetCode14. Longest Common Prefix
题目链接: https://leetcode.com/problems/longest-common-prefix/题目描述:找出所有字符串的最长公共前缀。题目分析:两个字符串的最长公共前缀,肯定不能超过其中短的字符串的长度。比较两个字符串1,2后找到了一个最长公共前缀长度为n,此时可以把前面的字符串2长度看成为n,再将字符串2与字符串3比较,再次找到一个新的最长公共前缀长度n_new,可以知原创 2016-01-13 18:19:06 · 446 阅读 · 0 评论 -
LeetCode165. Compare Version Numbers
题目链接: https://leetcode.com/problems/compare-version-numbers/题目描述:给出版本字符串,比较版本。Here is an example of version numbers ordering: 0.1 < 1.1 < 1.2 < 13.37题目分析:在遇到点之前的字符串如果转换成int型能比较出大小直接返回,如果相等,那么比较下一个点原创 2016-01-14 18:54:20 · 568 阅读 · 0 评论 -
nyoj448 寻找最大数
题目:描述 请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大,比如当n=92081346718538,m=10时,则新的最大数是9888输入 第一行输入一个正整数T,表示有T组测试数据 每组测试数据占一行,每行有两个数n,m(n可能是一个很大的整数,但其位数不超过100位,并且保证数据首位非0,m小于整数n的位数)输出 每组测试数据的输出占一行,输出剩余的数字按原次序组成原创 2016-02-26 20:59:17 · 562 阅读 · 0 评论 -
LeetCode290. Word Pattern
题目链接: https://leetcode.com/problems/word-pattern/题目描述:给一个模式和一个字符串,判断模式与字符串是否匹配。Examples: pattern = “abba”, str = “dog cat cat dog” should return true. pattern = “abba”, str = “dog cat cat fish” sh原创 2016-01-23 11:39:48 · 531 阅读 · 0 评论 -
LeetCode227. Basic Calculator II
题目链接: https://leetcode.com/problems/basic-calculator-ii/题目描述:计算字符串表达式的值。可能会有多余空格。题目分析:这道题对于我来说坑略多啊。字符串表达式中的数字可能为多位数。比如 345*16,第一次就跪这上面了,我没注意这个问题,以为只有个位。 这样解决就好。while (i < len && s[i] >= '0' && s[i原创 2016-01-22 17:50:19 · 573 阅读 · 0 评论 -
LeetCode273. Integer to English Words
题目链接: https://leetcode.com/problems/integer-to-english-words/题目描述:将整数转化成英语单词字符串For example, 123 -> “One Hundred Twenty Three” 12345 -> “Twelve Thousand Three Hundred Forty Five” 1234567 -> “One M原创 2016-01-17 18:12:58 · 551 阅读 · 0 评论 -
LeetCode43. Multiply Strings
题目链接: https://leetcode.com/problems/multiply-strings/题目描述:字符串实现大数相乘。题目分析:先给一个int型数组分配大小为num1.size()+num2.size(),用它存放两个字符串中每个数相乘的结果。num1第i位与num2第j位相乘,结果应当是放在第i+j+1位。如果i+j+1位有值,直接加上去。多加一个1是为了处理v[0]进位问原创 2016-01-19 14:03:27 · 409 阅读 · 0 评论 -
LeetCode5. Longest Palindromic Substring
题目链接: https://leetcode.com/problems/longest-palindromic-substring/题目描述:求最长回文子串。题目分析:感谢 http://blog.youkuaiyun.com/zhouworld16/article/details/16842467自己也想到过中间扩展,但是细节没有处理好。看了一下这篇博客,终于捋清思路了。嗯,回文字符串显然有个特征原创 2016-01-19 15:43:08 · 869 阅读 · 0 评论 -
LeetCode17. Letter Combinations of a Phone Number
题目链接: https://leetcode.com/problems/letter-combinations-of-a-phone-number/题目描述:给一个数字字符串,和一个数字的映射表,找出所有的字母组合。顺序可任意。Input:Digit string “23” Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “c原创 2016-01-20 08:34:42 · 436 阅读 · 0 评论 -
LeetCode49. Group Anagrams
题目链接: https://leetcode.com/problems/anagrams/题目描述:将给定的一组字符串数组,按照同构词(相同字母组成的单词)分类,每组单词按照字典排序。题目分析:哈希。先将字符串数组按字典序排一次,再构造map<string,vector<string>> hashMap,遍历字符串数组,将数组中每一个字符串按字典序排好,作为键值,这样就能将同构词放在同一组中。原创 2016-01-20 09:13:22 · 433 阅读 · 0 评论 -
LeetCode22. Generate Parentheses
题目链接: https://leetcode.com/problems/generate-parentheses/题目描述:给n对括号,求所有的合法括号组合。For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”题目分析: http://blog.csdn.ne原创 2016-01-20 10:10:58 · 627 阅读 · 0 评论 -
LeetCode71. Simplify Path
题目链接: https://leetcode.com/problems/simplify-path/题目描述:给定一个文档(Unix-style)的完全路径,请进行路径简化。题目分析:∑(っ °Д °;)っ一开始没懂题啊,咋简化啊。 最后查了才知道。路径简化的依据是:当遇到“/../”则需要返回上级目录,需检查上级目录是否为空。当遇到”/./”则表示是本级目录,无需做任何特殊操作。当遇到”/原创 2016-01-20 11:10:43 · 546 阅读 · 0 评论 -
LeetCode93. Restore IP Addresses
题目链接: https://leetcode.com/problems/restore-ip-addresses/题目描述:给定一个字符串,恢复并返回所有符合条件的IP串。For example: Given “25525511135”,return [“255.255.11.135”, “255.255.111.35”]. (Order does not matter)题目分析:IP分为4原创 2016-01-21 13:39:57 · 394 阅读 · 0 评论 -
LeetCode151. Reverse Words in a String
题目链接: https://leetcode.com/problems/reverse-words-in-a-string/题目描述:将字符串逆转。For example, Given s = “the sky is blue”, return “blue is sky the”.需要注意的是开头,中间,结尾可能会有多余的空格。麻烦的就是去掉多余的空格。分析:用istringstream的原创 2016-01-21 12:01:10 · 382 阅读 · 0 评论 -
LeetCode91. Decode Ways
题目链接: https://leetcode.com/problems/decode-ways/题目描述:求一个数字字符串的有多少编码方式。题目分析:嗯,一开始用递归去做超时了,应该是找递推式,动态规划。dp[i]代表对于字符串下标i(即字符串0~i)时的编码方式。1.当s[i]=0时,s[i-1]=1或s[i-1]=2,否则编码无效返回0。 dp[i]=dp[i-2]。此时应该将s[i-1原创 2016-01-22 12:37:50 · 632 阅读 · 0 评论 -
求最长公共子串
题目:给两个字符串,找出它们的最长的公共子串,跟求最长公共子序列不同,这个是求连续的。思路:动态规划。 dp[i][j]表示字符串a中[0~i]的子串,字符串b中[0~j]的子串,此时的最大长度。 如果a[i]==b[j],那么dp[i][j]=dp[i-1][j-1]+1; 如果a[i]不等于b[j],那么dp[i][j]=0。 变量end存放当前最长公共子串的最后一个元素的下标。 如果原创 2016-04-12 19:49:00 · 768 阅读 · 0 评论