随笔分类 - 哈希表
摘要:题目: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...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目: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...
阅读全文
摘要:题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:固定一个点,遍历其余点,期间用一个HashMap记录两点斜率和斜率次数,求出局部最大值;然...
阅读全文
摘要:下面参考java.util.HashMap,写了一个简单的散列表,只实现了其中的put和get方法,使用链接法"碰撞冲突"。代码最后,自定义了一个People类,并覆盖了equals,hashCode,toString方法,实现了Comparable接口。利用People类检验散列表的正确性,并利用...
阅读全文
摘要:思路:只需遍历一次数组,利用HashMap保存数组元素和下标,如果target-数组元素存在HashMap的key中,则返回结果,如果不存在,则put到HashMap中,注意,这种遍历保证了数组的下标肯定不小于HashMap中的下标。Java代码: public int[] twoSum(in...
阅读全文
浙公网安备 33010602011771号