上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页
摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.用 阅读全文
posted @ 2012-11-12 16:21 chkkch 阅读(7199) 评论(0) 推荐(0) 编辑
摘要: Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest palindromic substring.用一个指针从0遍历到s.size()-1,从里向外来检测子串是否是回文,分两种情况:1)bab, 2)bb。也就是当前指针可能指向的是奇数回文,也可能是偶数回文。做两次检测。 1 class Solution { 2 public: 3 string ... 阅读全文
posted @ 2012-11-12 16:07 chkkch 阅读(1703) 评论(1) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.模拟法,先选取第一个字符串,之后依次和后面的字符串得出LCP 1 class Solution { 2 public: 3 string longestCommonPrefix(vector<string> &strs) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function... 阅读全文
posted @ 2012-11-12 15:54 chkkch 阅读(968) 评论(0) 推荐(0) 编辑
摘要: 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"Output: ["ad", "ae", "af", "bd", "be", &q 阅读全文
posted @ 2012-11-12 11:30 chkkch 阅读(5341) 评论(0) 推荐(0) 编辑
摘要: Given a stringsconsists 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 defined as a character sequence consists of non-space characters only.For example,Givens="Hello Worl 阅读全文
posted @ 2012-11-12 11:12 chkkch 阅读(1567) 评论(0) 推荐(0) 编辑
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], returnfalse.用贪 阅读全文
posted @ 2012-11-12 10:46 chkkch 阅读(4493) 评论(1) 推荐(0) 编辑
摘要: Given n elements, sort the elements. Here, only one operation is permitted decreaseValue..Note that you cannot swap the values.. output should be a sorted list..if input is 4 5 2 1 3output is 3 3 3.. There can be many answers.. Give the optimum solution with minimum cost. where as cost is the sum of 阅读全文
posted @ 2012-11-09 21:51 chkkch 阅读(437) 评论(0) 推荐(0) 编辑
摘要: 1. There is a stream of numbers, design an effective datastructre to store the numbers and to return the median at any point of time.我们可以考虑维护一个max heap和一个min heap,max heap用来记录数组的前半部分, min heap用来记录数组的后半部分,返回数组的中位数时只要返回大堆的root。当有一个新的数字进来时,可虑是否大于min heap的root,大于的话就放到min heap,它属于数组的后半部分,如果这时min heap的大小大 阅读全文
posted @ 2012-11-09 20:58 chkkch 阅读(949) 评论(1) 推荐(0) 编辑
摘要: Given two arrays A & B of length l, containing non negative integers, such that the sum of integers in A is the same as sum of integers in B.( The numbers need not be the same in both the arrays.)Now if you start with an index 'k' in each array and do the following summation, SUMMATION ( 阅读全文
posted @ 2012-11-08 22:31 chkkch 阅读(392) 评论(0) 推荐(0) 编辑
摘要: 两次被问到这题了一次谷歌,一次百度,有必要好好弄清楚。先看这个题目,再看这个题目的推广。你有两个杯子,容量分别是a和b,你周围有自来水管(水无限),问能否量出c升水,也就是要求最终两个杯子中的水加起来是c升(c<=a+b)解:(1)设a和b的最大公约数是x,那么能量出c,当且仅当x能整除c。因为***(a,b)=x,则必然存在p和q,使得a*p+b*q=x。可以看到p和q必然一正一负,我们假设q为负(p为负的情况分析类似)。那么我们先考虑如何量出x升水,从等式上看,过程就是我们设法灌满a水杯p次,再倒出q次b升水,剩下的就是恰好x升水。举个例子吧:假设a=4,b=9,则b-2*a=1,那 阅读全文
posted @ 2012-11-07 23:47 chkkch 阅读(540) 评论(2) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页