08 2015 档案

摘要:难度:中等给k个字符串,求出他们的最长公共前缀(LCP)样例在 "ABCD" "ABEF" 和 "ACEF" 中, LCP 为 "A"在"ABCDEFG", "ABCEFG", "ABCEFA" 中, LCP 为 "ABC"答案: 1 public class Solution { 2 3... 阅读全文
posted @ 2015-08-31 20:12 -小城- 阅读(303) 评论(0) 推荐(0)
摘要:难度:中等给出两个字符串,找到最长公共子串,并返回其长度。样例给出A=“ABCD”,B=“CBCE”,返回 2。A=“www.lintcode.com code”,B=“www.ninechapter.com code”,返回 9。注意子串的字符应该连续的出现在原字符串中,这与子序列有所不同。答案:... 阅读全文
posted @ 2015-08-31 18:33 -小城- 阅读(237) 评论(1) 推荐(0)
摘要:难度:中等给出一个字符串数组S,找到其中所有的乱序字符串(Anagram)。如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中。样例对于字符串数组["lint","intl","inlt","code"]返回["lint","inlt","intl"]注意所有的字符串... 阅读全文
posted @ 2015-08-29 12:14 -小城- 阅读(315) 评论(0) 推荐(0)
摘要:难度:容易字符串查找(又称查找子字符串),是字符串操作中一个很有用的函数。你的任务是实现这个函数。对于一个给定的 source 字符串和一个 target 字符串,你应该在 source 字符串中找出 target 字符串出现的第一个位置(从0开始)。如果不存在,则返回-1。样例如果 source ... 阅读全文
posted @ 2015-08-29 02:41 -小城- 阅读(4446) 评论(0) 推荐(0)
摘要:难度:容易写出一个函数anagram(s, t)去判断两个字符串是否是颠倒字母顺序构成的。样例给出 s="abcd",t="dcab",返回true。S="abcd",T="aabd",返回false。答案: 1 public class Solution { 2 /** 3 * ... 阅读全文
posted @ 2015-08-29 01:26 -小城- 阅读(324) 评论(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 t... 阅读全文
posted @ 2015-08-29 00:50 -小城- 阅读(193) 评论(0) 推荐(0)
摘要:难度:难表Employee: 1 +----+-------+--------+--------------+ 2 | Id | Name | Salary | DepartmentId | 3 +----+-------+--------+--------------+ 4 | 1 | Joe... 阅读全文
posted @ 2015-08-28 14:54 -小城- 阅读(2808) 评论(0) 推荐(0)
摘要:难度:中等一个整数数组,除了一个数之外所有数字都出现了3次,找出这个数字来。注意: 你的算法应该是线性运行复杂度,且不能使用额外内存空间。答案:public class Solution { public int singleNumber(int[] nums) { int on... 阅读全文
posted @ 2015-08-27 22:36 -小城- 阅读(189) 评论(0) 推荐(0)
摘要:难度:中等一个整数数组,除了一个数之外所有数字都出现了2次,找出这个数字来。注意: 你的算法应该是线性运行复杂度,且不能使用额外内存空间。答案:public class Solution { public int singleNumber(int[] nums) { int n ... 阅读全文
posted @ 2015-08-27 22:35 -小城- 阅读(143) 评论(0) 推荐(0)
摘要:难度:中等写一段SQL查询至少连续出现3次的数字。+----+-----+| Id | Num |+----+-----+| 1 | 1 || 2 | 1 || 3 | 1 || 4 | 2 || 5 | 1 || 6 | 2 || 7 | 2 |+----... 阅读全文
posted @ 2015-08-27 12:02 -小城- 阅读(218) 评论(0) 推荐(0)
摘要:难度:中等写一段SQL语句查询分数排名情况。如果两个分数相等,则排名相同。+----+-------+| Id | Score |+----+-------+| 1 | 3.50 || 2 | 3.65 || 3 | 4.00 || 4 | 3.85 || 5 | 4.00 ||... 阅读全文
posted @ 2015-08-27 11:40 -小城- 阅读(233) 评论(0) 推荐(0)
摘要:难度:中等我们把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子7。习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。参考答案:public class Solution { public int nthUglyNumbe... 阅读全文
posted @ 2015-08-27 02:21 -小城- 阅读(549) 评论(0) 推荐(0)
摘要:难度:中等给定一个从 0, 1, 2, ...., n 包含了n个唯一数字的数组,查找数组中遗漏的那个数字。例如:数组nums=[0, 1, 3],则返回2。答案:public class Solution { public int missingNumber(int[] nums) { ... 阅读全文
posted @ 2015-08-27 00:29 -小城- 阅读(308) 评论(0) 推荐(0)
摘要:难度:容易写一段SQL,从表Employee查询第二高的收入。+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+例如,上面数据中第二高的收入... 阅读全文
posted @ 2015-08-26 21:39 -小城- 阅读(143) 评论(0) 推荐(0)
摘要:难度:容易给定Customers和Orders两个表,写一段SQL查询所有没有订购记录的客户。表:Customers.+----+-------+| Id | Name |+----+-------+| 1 | Joe || 2 | Henry || 3 | Sam || 4 | ... 阅读全文
posted @ 2015-08-26 21:13 -小城- 阅读(166) 评论(0) 推荐(0)
摘要:难度:容易给定表Weather,写一段SQL查询所有前一天温度高过当天温度的记录Id。+---------+------------+------------------+| Id(INT) | Date(DATE) | Temperature(INT) |+---------+----------... 阅读全文
posted @ 2015-08-26 20:26 -小城- 阅读(157) 评论(0) 推荐(0)
摘要:难度:容易写一段SQL语句,从表Person中删除所有重复的email记录,只保留最小Id的那条记录。+----+------------------+| Id | Email |+----+------------------+| 1 | john@example.com ... 阅读全文
posted @ 2015-08-26 20:00 -小城- 阅读(216) 评论(0) 推荐(0)
摘要:难度:中等表Employee保存了所有的员工数据。+----+-------+--------+--------------+| Id | Name | Salary | DepartmentId |+----+-------+--------+--------------+| 1 | Joe ... 阅读全文
posted @ 2015-08-24 21:08 -小城- 阅读(623) 评论(0) 推荐(0)
摘要:难度:容易写一段SQL,在表Person中查找所有重复的Email地址。+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d.com || 3 | a@b.com |+----+---------+例如... 阅读全文
posted @ 2015-08-24 21:07 -小城- 阅读(202) 评论(0) 推荐(0)