IncredibleThings

导航

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 28 下一页

2018年9月18日 #

LeetCode - Contains Duplicate III

摘要: “滑动窗口” + TreeSet TreeSet数据结构(Java)使用红黑树实现,是平衡二叉树的一种。 该数据结构支持如下操作: 1. floor()方法返set中≤给定元素的最大元素;如果不存在这样的元素,则返回 null。 2. ceiling()方法返回set中≥给定元素的最小元素;如果不存 阅读全文

posted @ 2018-09-18 10:32 IncredibleThings 阅读(106) 评论(0) 推荐(0) 编辑

2018年8月6日 #

LeetCode - Summary Ranges

摘要: 维护两个指针,start与end,如果nums[end+1] == nums[end],移动end,否则记录start到end的路径到list里。 阅读全文

posted @ 2018-08-06 10:53 IncredibleThings 阅读(116) 评论(0) 推荐(0) 编辑

2018年7月30日 #

LeetCode-Flip Game II

摘要: 若是有一段"++", 剩下的段和"--"组合 can not win, 那么返回true. 从头到尾试遍了没找到这么一段"++", 返回false. Time Complexity: exponential. T(n) = (n-2) * T(n-2) = (n-2) * (n-4) * T(n-4 阅读全文

posted @ 2018-07-30 00:12 IncredibleThings 阅读(73) 评论(0) 推荐(0) 编辑

2018年7月29日 #

LeetCode–Flip Game

摘要: 若是连着的"++", 就把这段用"--"替代放到res中. Note: 当i == s.length()-1走到最后一位时. s.substring(i+1), 不会out of index, 会返回"". 但再大就不行了. Time Complexity: O(n). Space: O(1) re 阅读全文

posted @ 2018-07-29 23:47 IncredibleThings 阅读(120) 评论(0) 推荐(0) 编辑

2018年7月27日 #

LeetCode – First Missing Positive

摘要: 虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。 思路:交换数组元素,使得数组中第i位存放数值(i+1)。最后遍历数组,寻找第一个不符合此要求的元素,返回其下标。整个过程需要遍历两次数组,复杂度为O(n)。 下图以题目中给出的第二个例子为例,讲解操作过程。 阅读全文

posted @ 2018-07-27 10:04 IncredibleThings 阅读(109) 评论(0) 推荐(0) 编辑

2018年7月22日 #

LeetCode – Group Shifted Strings

摘要: 与Group Anagrams类似. 维护一个HashMap, key是每个string 的 base型. Time Complexity: O(n * strings.length), n 是每个string的平均长度. Space: O(hm.size()), HashMap size. 阅读全文

posted @ 2018-07-22 23:44 IncredibleThings 阅读(163) 评论(0) 推荐(0) 编辑

2018年7月19日 #

LeetCode - Top K Frequent Elements

摘要: step1.显然,为了找出数组中出现频次最多的前k个元素,首先,我们需要分别统计出数组中各个元素出现的频次,很容易想到哈希表,Java中提供了HashMap类,它实现了Map接口,HashMap是一个泛型类(HashMap<key,value>),可以用来存储键/值对,为了统计数组个元素的频次,我们 阅读全文

posted @ 2018-07-19 10:57 IncredibleThings 阅读(111) 评论(0) 推荐(0) 编辑

2018年7月17日 #

LeetCode-H-Index II

摘要: 对于一个有序的序列,我们自然想到的就是二分查找算法。如何来做呢?我们画图分析一下: 1. 上图是一个递增的序列,下面一行是此处若满足条件对应的h值。可见h值是降序序列。因此在二分查找的过程中,如果某个h值满足条件(即h值小于它对应的值),我们就到前半部分继续查找;如果h值不满足条件(即h值大于它对应 阅读全文

posted @ 2018-07-17 10:49 IncredibleThings 阅读(111) 评论(0) 推荐(0) 编辑

2018年7月11日 #

LeetCode-H-Index

摘要: 1、将其发表的所有SCI论文按被引次数从高到低排序;2、从前往后查找排序后的列表,直到某篇论文的序号大于该论文被引次数。所得序号减一即为H指数。 阅读全文

posted @ 2018-07-11 10:25 IncredibleThings 阅读(80) 评论(0) 推荐(0) 编辑

LeetCode-Palindrome Pairs

摘要: Given a list of unique words, find all pairs of distinct indices (i, j) in the given list, so that the concatenation of the two words, i.e. words[i] + words[j] is a palindrome. Example 1: Given word... 阅读全文

posted @ 2018-07-11 10:09 IncredibleThings 阅读(107) 评论(0) 推荐(0) 编辑

上一页 1 ··· 10 11 12 13 14 15 16 17 18 ··· 28 下一页