上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 20 下一页
摘要: Q:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis at (i,ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.Note: Yo 阅读全文
posted @ 2013-09-19 10:04 summer_zhou 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Q:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.A:首先建立字符到数字的map.其次,分析罗马数字组成的规则,从字符串后面往前看,如果 if(dict[s[i+1]]>dict[s[i]]) sum-=dict[s[i]]; else sum+=dict[s[i]]; int romanToInt(string s) {... 阅读全文
posted @ 2013-09-18 23:00 summer_zhou 阅读(170) 评论(0) 推荐(0) 编辑
摘要: Q:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order ofO(logn).If the target is not found in the array, return[-1, -1].For example,Given[5, 7, 7, 8, 8, 10]and target value 8,return[3, 4].A: 二分查找 阅读全文
posted @ 2013-09-18 22:36 summer_zhou 阅读(262) 评论(0) 推荐(0) 编辑
摘要: Q:Divide two integers without using multiplication, division and mod operator.不用乘法,除法,取余实现两个int的相除。A: 二分的应用。如果按divident = divident-divisor,直至divident0&&divisor0)) bNegative = true; long long a = dividend,b=divisor; if(dividend=b) //注意是a>=b { sum = b; cnt = 1; while(sum+sum=b) { sum = b; c 阅读全文
posted @ 2013-09-18 16:56 summer_zhou 阅读(242) 评论(0) 推荐(0) 编辑
摘要: Q: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 @ 2013-09-18 12:55 summer_zhou 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Q:Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.Example 1:Given intervals[1,3],[6,9], insert and merge[2,5]in as[1,5],[6,9].Example 2:Given[1,2],[3,5],[6,7], 阅读全文
posted @ 2013-09-18 10:50 summer_zhou 阅读(150) 评论(0) 推荐(0) 编辑
摘要: Q:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.A:使用Map来处理。对cluster来说,最重要的是上界,下界和长度。对 阅读全文
posted @ 2013-09-17 17:04 summer_zhou 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Q:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.A: 重点是理解变位词的概念及其给所有词打tag:字典序 vector anagrams(vector &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function vector res; ... 阅读全文
posted @ 2013-09-17 10:59 summer_zhou 阅读(217) 评论(0) 推荐(0) 编辑
摘要: Q:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant space 阅读全文
posted @ 2013-09-16 23:01 summer_zhou 阅读(337) 评论(0) 推荐(0) 编辑
摘要: Q:A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it.For example,Given encoded message"12", it c 阅读全文
posted @ 2013-09-16 15:01 summer_zhou 阅读(152) 评论(0) 推荐(0) 编辑
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 20 下一页