
Leetcode----字符串
文章平均质量分 78
qq_2773878606
学生
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
最长回文子串
回文串是指这个字符串无论从左读还是从右读,所读的顺序是一样的;简而言之,回文串是左右对称的。现在,对于一个给定的母串 abcdedcb 可以找出子串a, ded, cdedc, bcdecdb等均是回文串;显然,bcdecdb是其中最长的那一个。但是该如何找出最长的回文子串呢? 穷举法 /*判断str[i..j]是否为回文串*/ int isPalindrome(char *s转载 2016-07-28 15:45:04 · 420 阅读 · 0 评论 -
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 va原创 2015-11-29 15:55:12 · 315 阅读 · 0 评论 -
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原创 2016-07-20 18:52:39 · 225 阅读 · 0 评论 -
String to Integer (atoi)
mplement 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 cas原创 2015-12-02 19:12:45 · 323 阅读 · 0 评论 -
Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with anot原创 2015-12-12 18:34:48 · 298 阅读 · 0 评论 -
Word Pattern
Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.原创 2015-12-12 18:52:57 · 268 阅读 · 0 评论 -
Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 就是在字符串haystack中找到needle 的位置。。。 class Solution { public: int原创 2015-12-14 09:13:07 · 325 阅读 · 0 评论 -
Reverse String
Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". #include #include #include using namespace std; string reverstring(stri原创 2016-07-07 09:33:20 · 313 阅读 · 0 评论 -
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". #include #include #include using namespace std; string reverword(s原创 2016-07-07 10:43:05 · 300 阅读 · 0 评论 -
Unique Characters of a String
Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure? #include #include using namespace std; bool iduniqle(string); int原创 2016-07-07 19:17:53 · 313 阅读 · 0 评论 -
Isomorphic Strings
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another原创 2016-07-07 19:33:26 · 254 阅读 · 0 评论 -
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". 这道题让我们原创 2016-07-08 08:55:02 · 225 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 思路: 1、两个输入时字符串,要变成数字,最后返回字符串。 2、进位的问题,相加的时候,是否产生进位,进位标志表示,进位则是1,否则为0, 怎原创 2015-11-28 17:42:01 · 390 阅读 · 0 评论 -
Compare Version Numbers
Compare two version numbers version1 and version1. If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0. You may assume that the version strings are non-empty and cont原创 2016-07-09 10:18:54 · 298 阅读 · 0 评论 -
Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a原创 2015-11-29 16:30:33 · 290 阅读 · 0 评论 -
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 defin原创 2016-07-07 18:15:00 · 298 阅读 · 0 评论 -
最长重复子串
首先这是一个单字符串问题。子字符串R 在字符串L 中至少出现两次,则称R 是L 的重复子串。重复子串又分为可重叠重复子串和不可重叠重复子串。 方法: KMP算法求解 在KMP算法的关键就是求解next数组,针对next[j]=k,可以得到P[0,1,...,k-1]=P[j-k,j-k+1,...,j-1]。看到P[0,1,...,k-1]=P[j-k,j-k+1,...,j-1转载 2016-07-28 16:10:07 · 722 阅读 · 0 评论 -
求字符串中最长无重复字符的子串
题目:求一个字符串中最长的没有重复字符的子串。 思路:用hash表从i遍历查看包含i的最长 无重复子串。 int max_unique_substring2(char * str) { int i,j; int begin; int maxlen = 0; int hash[256]; int n = strlen(str); for(原创 2016-07-28 15:29:50 · 882 阅读 · 0 评论 -
ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I原创 2015-11-28 14:56:00 · 305 阅读 · 0 评论