字符串
macans
止步就是退步
展开
-
LeetCode------------palindrome-partitioningII(回文2)
题目描述Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s原创 2016-10-05 16:09:49 · 330 阅读 · 0 评论 -
翻转子串
题目描述假定我们都知道非常高效的算法来检查一个单词是否为其他字符串的子串。请将这个算法编写成一个函数,给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成,要求只能调用一次检查子串的函数。给定两个字符串s1,s2,请返回bool值代表s2是否由s1旋转而成。字符串中字符为英文字母和空格,区分大小写,字符串长度小于等于1000。测试样例:"Hello wor原创 2016-10-20 20:23:30 · 381 阅读 · 0 评论 -
基本字符串压缩
题目描述利用字符重复出现的次数,编写一个方法,实现基本的字符串压缩功能。比如,字符串“aabcccccaaa”经压缩会变成“a2b1c5a3”。若压缩后的字符串没有变短,则返回原先的字符串。给定一个string iniString为待压缩的串(长度小于等于10000),保证串内字符均由大小写英文字母组成,返回一个string,为所求的压缩后或未变化的串。测试样例"a原创 2016-10-19 22:11:08 · 385 阅读 · 0 评论 -
确定两串乱序同构
题目描述给定两个字符串,请编写程序,确定其中一个字符串的字符重新排列后,能否变成另一个字符串。这里规定大小写为不同字符,且考虑字符串重点空格。给定一个string stringA和一个string stringB,请返回一个bool,代表两串是否重新排列后可相同。保证两串的长度都小于等于5000。测试样例:"This is nowcoder","is This no原创 2016-10-19 17:55:49 · 537 阅读 · 0 评论 -
确定字符互异
题目描述请实现一个算法,确定一个字符串的所有字符是否全都不同。这里我们要求不允许使用额外的存储结构。给定一个string iniString,请返回一个bool值,True代表所有字符全都不同,False代表存在相同的字符。保证字符串中的字符为ASCII字符。字符串的长度小于等于3000。测试样例:"aeiou"返回:True"BarackObama原创 2016-10-19 16:46:56 · 332 阅读 · 0 评论 -
原串翻转
题目描述请实现一个算法,在不使用额外数据结构和储存空间的情况下,翻转一个给定的字符串(可以使用单个过程变量)。给定一个string iniString,请返回一个string,为翻转后的字符串。保证字符串的长度小于等于5000。测试样例:"This is nowcoder"返回:"redocwon si sihT"思路:利用两个分别指向首字符和尾字符的ite原创 2016-10-19 17:05:26 · 461 阅读 · 0 评论 -
LeetCode:word-breakII
题目描述Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences.For examp原创 2016-10-06 09:10:48 · 260 阅读 · 0 评论 -
LeetCode----count-and-say
题目描述The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"two 1s"or21.21is read off原创 2016-10-18 21:48:10 · 352 阅读 · 0 评论 -
LeetCode------------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",Retu原创 2016-10-05 11:46:39 · 321 阅读 · 0 评论 -
字符串分隔
题目描述•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。输入描述:连续输入字符串(输入2次,每个字符串长度小于100)输出描述:输出到长度为8的新字符串数组输入例子:abc123456789输出例子:abc000001234567890000原创 2016-10-05 10:07:46 · 347 阅读 · 0 评论 -
evaluate-reverse-polish-notation(逆波兰表示求值)
//atoi (表示 ascii to integer)是把字符串转换成整型数:int atoi(const char *nptr);//string.c_str是Borland封装的String类中的一个函数,它返回当前字符串的首字符地址。class Solution {public: int evalRPN(vector &tokens) {原创 2016-09-21 22:10:02 · 455 阅读 · 0 评论 -
字符串最后一个单词的长度
C++语言求 字符串最后一个单词的长度原创 2016-09-22 19:33:00 · 403 阅读 · 0 评论 -
字符串的经典hash算法
1 概述链表查找的时间效率为O(N),二分法为log2N,B+ Tree为log2N,但Hash链表查找的时间效率为O(1)。 设计高效算法往往需要使用Hash链表,常数级的查找速度是任何别的算法无法比拟的,Hash链表的构造和冲突的不同实现方法对效率当然有一定的影响,然而Hash函数是Hash链表最核心的部分,本文尝试分析一些经典软件中使用到的字符串Hash函数在执行效率、离散性、空转载 2017-04-17 21:17:58 · 822 阅读 · 0 评论