![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
哈希
涛涛酱
北邮研究僧在读
展开
-
一致性哈希
传统的算法是hash值对结点个数取模,这样导致,结点增加或者删除的时候,数据迁移非常多。但是这种时候数据是均匀分布的。一致性哈希呢,把服务器hash到环上,然后根据数据hash到环上的位置决定放在哪个服务器上,这样解决了数据迁移多的问题,但是会产生数据分布不均衡的问题。增加虚拟节点来解决这个问题。【参考链接】https://www.zsythink.net/archives/1182...原创 2020-09-01 20:05:30 · 109 阅读 · 0 评论 -
【面试题】Continuous Subarray Sum 变形
题目描述给你一个数组和一个target,找出和是target整数倍的连续子串。思路要找出所有这样的子串。哈希表的val改成是所有的sum%target=n时,n对应的所有位置。然后每次遇见n时,哈希表中val中的所有left位置和当前位置之间组成合法子串。代码class Solution {public: vector<vector<int>> checkSubarraySum(vector<int>& nums, int k) {原创 2020-07-08 10:03:38 · 205 阅读 · 0 评论 -
【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: 4Explanation: The longest consecutive elements sequence is原创 2020-05-24 23:10:17 · 97 阅读 · 0 评论 -
【LeetCode 76】 Minimum Window Substring
题目描述Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:If there is no such window in S that covers all character原创 2020-05-24 22:23:26 · 103 阅读 · 0 评论 -
【LeetCode 146】 LRU Cache
题目描述Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key i...原创 2020-02-10 20:30:41 · 108 阅读 · 0 评论 -
【LeetCode 560】 Subarray Sum Equals K
题目描述Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1:Input:nums = [1,1,1], k = 2Output: 2Note:The length of...原创 2020-02-03 17:53:01 · 67 阅读 · 0 评论 -
【LeetCode 128. 】Longest Consecutive Sequence
题目大意:给出一个数组,求里面的数字能组成的最长连续序列的长度。要求在 O (n) 时间内。思路:哈希表,遍历数组中的数字 num, 根据 num-1和 num+1的长度来更新。枚举数组中的数字num, 当num-1不在数组中时,num是一个序列的起始,查找。代码:代码1:class Solution {public: int longestConsecutive(v...原创 2019-07-04 20:19:34 · 90 阅读 · 0 评论