随笔分类 - String
摘要:Compare two strings A and B, determine whether A contains all of the characters in B. The characters in string A and B are all Upper Case letters. Not
阅读全文
摘要:Reverse Words in a String I Given an input string, reverse the string word by word. For example,Given s = "the sky is blue",return "blue is sky the".
阅读全文
摘要:For a given source string and a target string, you should output the first index(from 0) of target string in source string. If target does not exist i
阅读全文
摘要:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the
阅读全文
posted @ 2015-06-24 01:00
北叶青藤
摘要:Question: Find the longest sub-string without repeating characters. For example, if the given string is "abcdcefg", the longest sub-string is "dcefg".
阅读全文
摘要:Word Break I Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionar
阅读全文
摘要:Question: Give a string, use minimum number of splits to divide the string into multiple parts in which each part a palindrome. For example, if the st
阅读全文
摘要:Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. The key part is i <= haystack.length() - nee
阅读全文
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan
阅读全文
摘要: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
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings. For instance: ["ab", "bc"] returns ""; ["a", "ab"] re
阅读全文
摘要:把字符串前面的若干个字符移动到字符串的尾部。如把字符串abcdef前2位字符移到后面得到字符串cdefab。要求时间对长度为n的字符串操作的复杂度为O(n),辅助内存为O(1)。 分析:如果不考虑时间和空间复杂度的限制,最简单的方法莫过于把这道题看成是把字符串分成前后两部分,把原字符串后半部分拷贝到
阅读全文
摘要:问题: 这是我今天面试时遇到的一道题。要求不使用循环反转字符串,当时被卡住了,一直没有想到要用递归,后面面试官提示用递归,才想到,哎。 分析: 递归的思路是:构建一个方法,该方法把返回从0到 i 的反转字符串,如果i = 0, 返回当前字符。 转载请注明出处。
阅读全文
摘要:问题: 把字符串压缩,比如aaabbbbc, 压缩后成为:a3b4c1。 分析: 这题很简单,我们只需要从头到尾遍历一遍字符串即可。首先设置一个计数器count, 每次“指针移位”的时候,判断当前字符是否与前一个字符相等,如果相等,count++, 指针继续下移,否则,我们需要对前面已经遍历的字符串
阅读全文
摘要:问题: 所谓 anagram, 就是两个词所用的字母及其个数都是一样的,但是,字母的位置不一样。比如 abcc 和 cbca 就是 anagram. 分析: 判断的方法比较简单,先把单个字母(字符)转成整数,然后利用了hashtable+计数器的原理进行判断。 转载请注明出处。
阅读全文
摘要:问题: 有两个字符串,每个字符串的字符从A-Z中选取,比如: B = “ABBC”, A = “ACBBD”。那么A包含所有B中出现的字符。如果A = “ACBD” 或者 A = “ABBD”,则我们认为A不包含B中所有的字符。 分析: 对于“是否包含”的问题,基本上处理的方法都会与hashtabl
阅读全文
摘要:问题: 给定一个字符串,比如 A = “ABCDACD”, 找出第一个只出现一次的字符,在A中,第一个只出现一次的字符是‘B’。 分析: 为了判定某字符是否出现一次,我们可以从从头开始往下遍历,如果没有重复,则选取,否则抛弃。这样做的话复杂度为 O(n^2)。其实,对于判定是否存在或者存在的次数等问
阅读全文
摘要:给一个字符串,比如“Ilovechina”,把字符反转后变成“chinaloveI”思路:先把字符串从第一个字符与最后一个字符对换,第二个字符和倒数第二个字符对换,这样,我们就把每一个单词位置互换了。但是我们要求单词里面字符的顺序是不能变的,所以,我们要把每一个单词里面的字符从头到尾对换一下。这样就...
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent. Example Given "23" Return ["ad", "ae", "af", "bd", "be"
阅读全文

浙公网安备 33010602011771号