leetcode-string
shanshanhi
这个作者很懒,什么都没留下…
展开
-
344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”.string reverseString(string s) { int j = s.size() - 1; int i =原创 2017-02-27 20:09:08 · 272 阅读 · 0 评论 -
38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, the原创 2017-03-02 11:29:13 · 385 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
Given a digit string, 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. Input:Digit string “23”原创 2017-03-02 12:45:43 · 221 阅读 · 0 评论 -
49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], Return:[ [“ate”, “eat”,”tea”], [“nat”,”tan”], [“bat”] ] Note: All inputs原创 2017-03-02 13:03:26 · 234 阅读 · 0 评论 -
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string. If the last word does not exist, return 0. Note: A word is define原创 2017-03-02 13:10:39 · 207 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 直接相加string addBinary(string a, string b) { int lena = a.length() - 1; i原创 2017-03-02 13:32:26 · 252 阅读 · 0 评论 -
72. Edit Distance
编辑距离概念描述:编辑距离,又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。例如将kitten一字转成sitting:sitten (k→s)sittin (e→i)sitting (→g)俄罗斯科学家Vladimir Levenshtein在1965年提出这个概念。 问题:找出字符...原创 2017-03-02 13:57:42 · 256 阅读 · 0 评论 -
115. Distinct Subsequences--动态规划的方法
题目Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can转载 2017-03-02 16:39:36 · 496 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.//由于字符串数组中所有字符的最长公共子串存在于所有字符串中,所以从strs[0]的字符中依次取一个字符串出来,在剩下的strs.size()-1个字符串中进行判断string longestCommonPrefix(vecto原创 2017-03-01 21:01:50 · 209 阅读 · 0 评论 -
434. Number of Segments in a String
Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters. Please note that the string does not contain any non-printable characters. Ex原创 2017-03-02 11:15:52 · 314 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters--重要
Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the answer is “b”, with原创 2017-03-01 20:01:12 · 227 阅读 · 0 评论 -
345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”.Note: The vowels原创 2017-02-27 20:20:32 · 218 阅读 · 0 评论 -
8. String to Integer (atoi) --重要
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases.N原创 2017-02-27 21:17:55 · 240 阅读 · 0 评论 -
520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the following cases holds: All letters in this w原创 2017-02-28 20:34:58 · 303 阅读 · 0 评论 -
383. Ransom Note--哈希的方法
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; oth原创 2017-02-28 20:45:08 · 342 阅读 · 0 评论 -
13. Roman to Integer
第一题、13. Roman to Integer Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 解题思路: 罗马数字是符号和加操作的一个组合。他基于以下七个符号。 II is 2, and XIII is 13. 罗马原创 2017-02-28 21:49:05 · 241 阅读 · 0 评论 -
151. Reverse Words in a String
Given an input string, reverse the string word by word. For example, Given s = “the sky is blue”, return “blue is sky the”. Update (2015-02-12): For C programmers: Try to solve it in-place in O(1)原创 2017-02-28 20:09:14 · 288 阅读 · 0 评论 -
22. Generate Parentheses--递归法
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: [ “((()))”, “(()())”, “(())()”, “()(()原创 2017-03-01 09:53:59 · 467 阅读 · 0 评论 -
20. Valid Parentheses
Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the correct order, “()” and “()[]{}” are all valid but “原创 2017-03-01 10:04:28 · 217 阅读 · 0 评论 -
5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.分析:采用中转载 2017-03-02 17:14:46 · 395 阅读 · 0 评论