随笔分类 -  哈希表

摘要:题目:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure y... 阅读全文
posted @ 2015-12-10 20:43 lasclocker 阅读(2019) 评论(0) 推荐(0)
摘要:题目:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.Accordi... 阅读全文
posted @ 2015-11-08 20:37 lasclocker 阅读(333) 评论(0) 推荐(0)
摘要:题目:Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a let... 阅读全文
posted @ 2015-11-01 16:11 lasclocker 阅读(174) 评论(0) 推荐(0)
摘要:题目:You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret number and ask your friend to guess it, each time yo... 阅读全文
posted @ 2015-10-31 22:01 lasclocker 阅读(221) 评论(0) 推荐(0)
摘要:题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:固定一个点,遍历其余点,期间用一个HashMap记录两点斜率和斜率次数,求出局部最大值;然... 阅读全文
posted @ 2015-10-21 10:45 lasclocker 阅读(274) 评论(0) 推荐(0)
摘要:下面参考java.util.HashMap,写了一个简单的散列表,只实现了其中的put和get方法,使用链接法"碰撞冲突"。代码最后,自定义了一个People类,并覆盖了equals,hashCode,toString方法,实现了Comparable接口。利用People类检验散列表的正确性,并利用... 阅读全文
posted @ 2015-10-06 21:21 lasclocker 阅读(378) 评论(0) 推荐(0)
摘要:思路:只需遍历一次数组,利用HashMap保存数组元素和下标,如果target-数组元素存在HashMap的key中,则返回结果,如果不存在,则put到HashMap中,注意,这种遍历保证了数组的下标肯定不小于HashMap中的下标。Java代码: public int[] twoSum(in... 阅读全文
posted @ 2015-08-08 14:36 lasclocker 阅读(114) 评论(0) 推荐(0)