摘要: Write a function to find the longest common prefix string amongst an array of strings.方法1:BF, 首先计算两个字符串的prefix,每次用这个prefix与下一个字符串生成新的prefix效果较差,大数据集直接挂了,代码可读性太差-_-! 1 public String longestCommonPrefix(String[] strs) { 2 // Start typing your Java solution below 3 // DO NOT write main(... 阅读全文
posted @ 2013-06-27 20:11 feiling 阅读(1101) 评论(0) 推荐(0) 编辑
摘要: 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: You 阅读全文
posted @ 2013-06-27 16:32 feiling 阅读(327) 评论(0) 推荐(0) 编辑
摘要: Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of converting the integer to string, note the restriction of using extra space.You could also try reversing an integer. However, if you have solved 阅读全文
posted @ 2013-06-27 10:58 feiling 阅读(514) 评论(0) 推荐(0) 编辑
摘要: Implementatoito 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 cases.Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). You are respo 阅读全文
posted @ 2013-06-27 10:29 feiling 阅读(223) 评论(0) 推荐(0) 编辑