
Hash
iteye_17352
这个作者很懒,什么都没留下…
展开
-
Leetcode - Two Sum
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 numbers such that they add up to the target, whe...原创 2015-07-20 10:14:57 · 63 阅读 · 0 评论 -
Leetcode - Max Points on a Line
[分析]两条直线若包含一个公共点且斜率相同,则为同一条直线。因此依次将数组中各点设为公共点,并计算所有未当过公共点的其他点同当当前公共点形成直线的斜率,使用哈希表保存各斜率直线上的点数,遍历过程中同时更新维护一条直线上包含的最多点数。实现1中key直接就是double类型的斜率,实现时有几个注意点:1)斜率为0时要单独判断并显式赋值为0,double类型0 和 -0是不等的2)需要...原创 2015-08-23 15:30:26 · 140 阅读 · 0 评论 -
Leetcode - Fraction to Recurring Decimal
[分析][color=blue]处理int型整数运算时,为避免溢出,省事的做法就是内部转为long类型处理[/color],不然极可能在极值case上栽跟头,比如int a = Integer.MIN_VALUE, int b = -1 和 long a = Integer.MIN_VALUE, long b = -1, 两者a / b的结果是不一样的,前者会发生溢出,在比如Math.ab...原创 2015-08-23 10:05:03 · 106 阅读 · 0 评论 -
Leetcode - Isomorphic Strings
[分析]思路1:维护两个哈希表,char[] map, boolean[] used, 长度均为256,map[charS] = charT, 表示将字符charS 映射为charT, used[charT]==true 表示charT已经被某个字符映射过了。同步遍历字符串s & t,记两者当前的字符分别为charS, charT, 若charS是新字符,且charT没有被使用,则我们可将其同...原创 2015-08-23 09:51:03 · 78 阅读 · 0 评论 -
Leetcode - Palindrome Permutation
[分析]思路2让我大开眼界,顺便学习下BitSet~[ref][url]https://leetcode.com/discuss/53180/1-4-lines-python-ruby-c-c-java[/url][code="java"]public class Solution { // Method 2: https://leetcode.com/discu...原创 2015-08-22 16:24:14 · 117 阅读 · 0 评论 -
Leetcode - Group Shifted String
Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:"abc" -> "bcd" -> ... -> &q原创 2015-08-22 16:20:31 · 129 阅读 · 0 评论 -
Leetcode - Two Sum III - Data Structure Design
[分析]find的version1 版本注意num2Occur 需定义为Integer类型,建议version2版本[ref][url]https://leetcode.com/discuss/19515/my-solutions-java-and-python-time-for-add-time-for-find-space[/url][code="java"]pub...原创 2015-08-21 10:30:33 · 109 阅读 · 0 评论 -
Leetcode - Longest Consecutive Sequence
[分析]base version说几句:[color=red]数组题一定要考虑重复重复重复的问题[/color]!另外循环结束要记得最后一次更新maxLenO(N)解法思路请移步[url]http://blog.youkuaiyun.com/linhuanmars/article/details/22964467[/url][code="java"]public class Solut...原创 2015-08-20 21:20:41 · 74 阅读 · 0 评论 -
Leetcode - Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k.[分析]...原创 2015-08-18 07:57:15 · 72 阅读 · 0 评论 -
Leetcode - Shortest Word Distance II
This is a follow up of Shortest Word Distance. The only difference is now you are given the list of words and your method will be called repeatedly many times with different parameters. How would you ...原创 2015-08-18 07:25:35 · 97 阅读 · 0 评论 -
Leetcode - Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri...原创 2015-08-17 13:43:04 · 99 阅读 · 0 评论 -
Leetcode - LRU Cache
[分析]自己使用HashMap + LinkedList/ArrayList的都会超时,讨论区看到使用LinkedHashMap实现的版本[url]https://leetcode.com/discuss/42891/probably-the-best-java-solution-extend-linkedhashmap[/url],这个数据结构自己平常没用过,正好学习了~[code=...原创 2015-09-03 18:31:44 · 119 阅读 · 0 评论