![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Hash
Wade_Gao
这个作者很懒,什么都没留下…
展开
-
数据结构与算法题目集(中文)7-15 QQ帐户的申请与登陆 (25分)
一、解题思路采用unordered_map建立起QQ号和pwd的映射,仅此而已二、解题代码#include <iostream>#include <string>#include <unordered_map>using namespace std;int main(){ int N; cin >> N; unordered_map<string, string> ump; for(int i = .原创 2020-07-04 23:41:00 · 209 阅读 · 0 评论 -
浙大版《数据结构(第2版)》题目集5.10 线性探测法的查找函数 (20分)
一、题目描述#include <stdio.h>#define MAXTABLESIZE 100000 /* 允许开辟的最大散列表长度 */typedef int ElementType; /* 关键词类型用整型 */typedef int Index; /* 散列地址类型 */typedef Index Position; /* 数据所在位置与散列地址是同一类型 *//* 散列单元状态类型,分别对应:有合法元素、空单元、有已删除元素 */原创 2020-06-24 12:25:07 · 389 阅读 · 0 评论 -
LeetCode-560: 和为K的子数组
First. Problem’s DescriptionSecond. Problem’s SolutionUse a HashTable to store the pre_sum of the array, use unordered_map<sum, how_many> ump;When we start, insert pair<int, int>(0, 1)into the unordered_map first, that represents even if t原创 2020-06-07 17:02:19 · 113 阅读 · 0 评论 -
LeetCode-1:两数之和
一、题目描述二、解题思路这道题当然可以暴力,这样时间复杂度为O(n2)O(n^2)O(n2)。所以我采用哈希表来解决。遍历一次数组,将其与下标的pair(val,index)pair(val, index)pair(val,index)插入到哈希表中。所以我们根据当前的数字去找target−nums[i]target - nums[i]target−nums[i]是否在哈希表里即可。但是如果出现target−nums[i]==nums[i]target - nums[i] == nums[i]tar原创 2020-06-04 20:02:17 · 127 阅读 · 0 评论 -
LeetCode-432:全 O(1) 的数据结构
一、题目描述二、解题思路三、解题代码class AllOne{private: class Node { public: string str; int num; Node(string s, int n) { str = s; num = n; } friend bool operator<(const Node &原创 2020-05-20 23:59:23 · 516 阅读 · 0 评论 -
LeetCode-355:设计推特
class Twitter{private: vector<pair<int, int>> Msg; unordered_map<int, set<int>> Fler;public: Twitter() { } void postTweet(int userId, int tweetId) { Msg.push_back(make_pair(userId, tweetId));原创 2020-05-17 22:36:32 · 121 阅读 · 0 评论 -
LeetCode面试题 16.02: 单词频率
First. Problem’s DescriptionSecond. Problem’s SolutionWe can simply use a unordered_map to solve this problem, which core is powered by HashBy the way, the default initial value is 000Three. Code For Solutionclass WordsFrequency {private: unorde原创 2020-05-12 21:05:00 · 174 阅读 · 0 评论 -
LeetCode-648:单词替换
一、题目描述二、解题思路用双指针法切割字符串,得到每一个单词,然后开始遍历字典首先判断单词首字母和字典当前元素的首字母是否相等,相等继续进行下一步,否则肯定不是判断当前单词的前缀是否等于字典当前元素如果以上两个条件都满足,就把单词替换成词根,注意这个动作完成后不能直接break因为有可能存在继承词有许多可以形成词根的情况,我们需要找到最短的,比如:["catt","cat","bat...原创 2020-05-07 16:03:50 · 343 阅读 · 0 评论 -
LeetCode-面试题01.04:回文排列
一、题目描述二、解题思路就是用一个Hash表存储字符串中出现过的字符,待字符串遍历完成后,再遍历一遍Hash表,如果出现次数为奇数的字母超过1个,就不可能重组为回文串,否则就可以重组为回文串。三、解题代码class Solution {public: bool canPermutePalindrome(string s) { vector<int> ...原创 2020-05-07 15:43:31 · 141 阅读 · 0 评论 -
LeetCode-3:无重复字符的最长子串
一、题目描述二、解题思路采用一个Hash表,记录出现的频次,再采用一个last数组,当检查到某一位字母重复出现时,记录该字母上次出现的地方。之所以要保存上次出现的位置,看下面的例子:"AKVFWCEMCNBguywesgfceuyr3275468372trgcoiwgyagaoeufcageoGIC"我们第一次查重,会找到第八位C在之前出现过,那么我们需要将l右移,但是不能直接移动到r处...原创 2020-05-02 15:45:40 · 98 阅读 · 0 评论 -
LeetCode-609: 在系统中查找重复文件
First: Problem’s DescriptionSecond: Problem’s SolutionWe can useclass Solution {private: pair<string, string> CreateDocPair(string str, string rootPath){ int prior = 0; ...原创 2020-05-02 00:47:31 · 143 阅读 · 0 评论 -
LeetCode-1160: 拼写单词
First: Problem’s DescriptionSecond: Problem’s SolutionEvidently we can use a hash vector to save the frequency of the letters in chars. then we traverse the vector wordsand each time we traverse a ...原创 2020-05-01 22:37:58 · 122 阅读 · 0 评论 -
LeetCode-36有效的数独
First. Problem’s DescriptionSecond. Problem’s SolutionI think that he only important thing is how to judge if the each of the nine sublocks containing 9 numbers derived from the given Sudoku comply...原创 2020-04-30 17:20:22 · 86 阅读 · 0 评论 -
LeetCode-202:快乐数
一、题目描述二、解题思路在计算的过程中,只要当前得到的数字在之前出现过,就说明一定不快乐,直接返回false就好了这里可以用一个set来记录之前的数字是否出现过set.find(x):找到了返回迭代器位置,否则返回set.end()三、解题代码class Solution {public: bool isHappy(int n) { set<int&g...原创 2020-04-30 01:05:22 · 109 阅读 · 0 评论