06 2013 档案

摘要: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 阅读(329) 评论(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 阅读(516) 评论(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 阅读(227) 评论(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.O(n*n)。对于每一个字符,以之作为中间元素往左右寻找。注意处理奇偶两种模式:1. aba2. abba 1 public class Solution { 2 public String longestPalindrome(String s) { ... 阅读全文
posted @ 2013-06-17 10:54 feiling 阅读(273) 评论(0) 推荐(0) 编辑
摘要: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 @ 2013-06-17 09:41 feiling 阅读(258) 评论(0) 推荐(0) 编辑
摘要:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single ... 阅读全文
posted @ 2013-06-16 17:00 feiling 阅读(237) 评论(0) 推荐(0) 编辑
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).比较容易想到的做法是O(n),merge两个数组,然后求中值。 1 public class Solution { 2 public double findMedianSortedArrays(int A[], int B[]) { 3 // Sta... 阅读全文
posted @ 2013-06-15 18:07 feiling 阅读(463) 评论(0) 推荐(0) 编辑
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu... 阅读全文
posted @ 2013-06-15 17:50 feiling 阅读(228) 评论(0) 推荐(0) 编辑
摘要:1.两种比较接口分析在“集合框架”中有两种比较接口:Comparable接口和Comparator接口。Comparable是通用的接口,用户可以实现它来完成自己特定的比较,而Comparator可以看成一种算法的实现,在需要容器集合实现比较功能的时候,来指定这个比较器,这可以看成一种设计模式,将算法和数据分离。前者应该比较固定,和一个具体类相绑定,而后者比较灵活,它可以被用于各个需要比较功能的类使用。一个类实现了Camparable接口表明这个类的对象之间是可以相互比较的。如果用数学语言描述的话就是这个类的对象组成的集合中存在一个全序。这样,这个类对象组成的集合就可以使用Sort方法排序了。 阅读全文
posted @ 2013-06-10 16:36 feiling 阅读(291) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示