
LeetCode哈希表
肉丸不肉
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode 128. Longest Consecutive Sequence(最长连续子序列)
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2]Output: 4Exp...原创 2020-03-13 14:29:23 · 235 阅读 · 0 评论 -
LeetCode 594. Longest Harmonious Subsequence(最长和谐子序列)
Example 1:Input: [1,3,2,2,5,2,3,7]Output: 5Explanation: The longest harmonious subsequence is [3,2,2,2,3].需要统计“个数”—hashmap public int findLHS(int[] nums) { HashMap<Integer, Inte...原创 2020-03-13 14:12:27 · 229 阅读 · 0 评论 -
LeetCode 217. Contains Duplicate(存在重复元素)
Example 1:Input: [1,2,3,1]Output: trueExample 2:Input: [1,2,3,4]Output: falseExample 3:Input: [1,1,1,3,3,4,3,2,4,2]Output: trueHashSet 去重,判断是否存在重复元素写法一:用contains(key) public boolean...原创 2020-03-13 13:45:12 · 268 阅读 · 0 评论 -
LeetCode 1. Two Sum(两数之和,返回索引)
法一、递增排序+双指针时间复杂度为O(NlogN),空间复杂度为O(1)法二、HashMap时间复杂度为O(N),空间复杂度为O(N)空间换时间 public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); ...原创 2020-03-13 13:39:55 · 260 阅读 · 0 评论 -
哈希表原理+题目总结
哈希表是一种数据结构,它使用哈希函数组织数据,以支持快速插入和搜索。哈希表的关键思想是使用哈希函数将键映射到存储桶哈希表使用 O(N) 空间复杂度存储数据,并且以 O(1) 时间复杂度求解问题。哈希函数/散列函数冲突解决有两种不同类型的哈希表:哈希集合和哈希映射。哈希集合是集合数据结构的实现之一,用于存储非重复值。使用哈希集查重哈希映射是映射 数据结构的实现之一,...原创 2020-03-13 13:29:24 · 704 阅读 · 0 评论