当前位置: 首页 > news >正文

wordpress怎么搬家重庆网站优化软件

wordpress怎么搬家,重庆网站优化软件,知名的网络公司,如何加强省市网站建设【ps】本篇有 5 道 leetcode OJ。 一、算法简介 哈希表是一种存储数据的容器,可以快速查找某个元素,其查找的时间复杂度为 O(1),非常合适需要频繁查找某一个元素的场景。其具体用法为: 直接使用底层为哈希表的 STL 容器。用数组…

【ps】本篇有 5 道 leetcode OJ。 

一、算法简介

        哈希表是一种存储数据的容器,可以快速查找某个元素,其查找的时间复杂度为 O(1),非常合适需要频繁查找某一个元素的场景。其具体用法为:

  • 直接使用底层为哈希表的 STL 容器。
  • 用数组模拟简易的哈希表,例如利用数组统计字符串中字符的频次、整型的数据范围很小时映射某些值等。

二、相关例题

1)两数之和

1. 两数之和

.1- 题目解析

        不难想到暴力解法,两层 for 循环将所有组合枚举一遍,即可找到答案。 

        不过,我们还可以用一个 unordered_map 来记录原始数组中每个元素的下标,而要找到和为  target 的两个元素,只需在遍历到原始数组中一个元素 x 时,查询哈希表中是否有值为 target - x 的原始数组元素,有则返回这两个元素作为最终结果。

.2- 代码编写

class Solution {
public:vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int,int> hash;for(int i=0;i<nums.size();i++){int x=target-nums[i];//有则返回结果if(hash.count(x))return {hash[x],i};//将当前元素统计入哈希表hash[nums[i]]=i;}return {-1,-1};}
};

2)判定是否互为字符重排

面试题 01.02. 判定是否互为字符重排

.1- 题目解析

        如果两个字符串 s1 和 s2 是互为字符重排的,那么它们中的字符相应出现的频次是相同的,我们可以用一个数组来模拟哈希表,统计两个字符串中字符出现的频次。

.2- 代码编写

//写法1:用两个哈希表分别统计后再比对
class Solution {
public:bool CheckPermutation(string s1, string s2) {if(s1.size()!=s2.size())return false;int hash1[26]={0};int hash2[26]={0};for(auto ch:s1)hash1[ch-'a']++;for(auto ch:s2){hash2[ch-'a']++;}for(int i=0;i<26;i++){if(hash1[i]!=hash2[i])return false;}return true;}
};
//写法2:用一个哈希表来统计和比对
class Solution {
public:bool CheckPermutation(string s1, string s2) {if(s1.size()!=s2.size())return false;int hash[26]={0};for(auto ch:s1)hash[ch-'a']++;for(auto ch:s2){hash[ch-'a']--;if(hash[ch-'a']<0)return false;}return true;}
};

3)存在重复元素

217. 存在重复元素

.1- 题目解析

        直接用一个哈希表统计数字出现的频次即可。

.2- 代码编写

class Solution {
public:bool containsDuplicate(vector<int>& nums) {unordered_map<int,int> hash;for(auto x:nums){hash[x]++;if(hash[x]%2==0)return true;}return false;}

4)存在重复元素 II

219. 存在重复元素 II

.1- 题目解析

        这道题相较于上一道,哈希表的映射关系不再是 <数字,频次>,而应是 <数字,在原数组中的下标>;返回条件不再是数字出现的频次为 2,而是相同两数的下标之差小于 k。

 

.2- 代码编写

class Solution {
public:bool containsNearbyDuplicate(vector<int>& nums, int k) {unordered_map<int,int> hash;for(int i=0;i<nums.size();i++){if(hash.count(nums[i])){if(i-hash[nums[i]]<=k)return true;}hash[nums[i]]=i;}return false;}
};

5)字母异位词分组

49. 字母异位词分组

.1- 题目解析

        字母异位词之间,字符出现的频次是相同的。我们可以对每一个词通过 ascii 码来进行排序,将排序结果相同的放在一起,即放在一个字符串数组中,由此,我们可以用一个哈希表来存储结果,哈希表中的映射关系是 <排序后的字符串,同组的字母异位词>。

.2- 代码编写

class Solution {
public:vector<vector<string>> groupAnagrams(vector<string>& strs) {//用哈希表对字母异位词分组unordered_map<string,vector<string>> hash;for(auto& s:strs){string tmp=s;sort(tmp.begin(),tmp.end());hash[tmp].push_back(s);}//构建返回结果vector<vector<string>> ret;for(auto&[x,y]:hash)ret.push_back(y);return ret;}
};


文章转载自:
http://courtesy.rywn.cn
http://buccaneerish.rywn.cn
http://aneurism.rywn.cn
http://sporangiospore.rywn.cn
http://tangly.rywn.cn
http://singhalese.rywn.cn
http://volleyball.rywn.cn
http://lucas.rywn.cn
http://beld.rywn.cn
http://rooming.rywn.cn
http://agname.rywn.cn
http://saccharoidal.rywn.cn
http://datto.rywn.cn
http://mcat.rywn.cn
http://dredge.rywn.cn
http://spissatus.rywn.cn
http://condensed.rywn.cn
http://hamah.rywn.cn
http://christology.rywn.cn
http://shaken.rywn.cn
http://outport.rywn.cn
http://warta.rywn.cn
http://chummery.rywn.cn
http://candlepin.rywn.cn
http://cooperage.rywn.cn
http://pacification.rywn.cn
http://lashings.rywn.cn
http://drudgery.rywn.cn
http://brassiere.rywn.cn
http://overactive.rywn.cn
http://cali.rywn.cn
http://reconsignment.rywn.cn
http://zoopathology.rywn.cn
http://gilberte.rywn.cn
http://courser.rywn.cn
http://shaking.rywn.cn
http://lag.rywn.cn
http://meager.rywn.cn
http://spongoid.rywn.cn
http://backen.rywn.cn
http://pimp.rywn.cn
http://verticillium.rywn.cn
http://cesspool.rywn.cn
http://gellant.rywn.cn
http://antibiosis.rywn.cn
http://cribble.rywn.cn
http://birdfarm.rywn.cn
http://sinapin.rywn.cn
http://brachistochrone.rywn.cn
http://idolism.rywn.cn
http://unparliamentary.rywn.cn
http://lathework.rywn.cn
http://digressively.rywn.cn
http://unheedingly.rywn.cn
http://cribellum.rywn.cn
http://microgamete.rywn.cn
http://sisterhood.rywn.cn
http://monohydrate.rywn.cn
http://rapt.rywn.cn
http://upsweep.rywn.cn
http://neanthropic.rywn.cn
http://oneirology.rywn.cn
http://accommodative.rywn.cn
http://dreyfusard.rywn.cn
http://aeronef.rywn.cn
http://avalanchine.rywn.cn
http://transmission.rywn.cn
http://walhalla.rywn.cn
http://formalism.rywn.cn
http://whangarei.rywn.cn
http://irresolution.rywn.cn
http://demonstrability.rywn.cn
http://incunable.rywn.cn
http://intussusception.rywn.cn
http://xylophilous.rywn.cn
http://czechize.rywn.cn
http://unclimbable.rywn.cn
http://organic.rywn.cn
http://subfuscous.rywn.cn
http://welfarism.rywn.cn
http://acouchi.rywn.cn
http://phallical.rywn.cn
http://afterwit.rywn.cn
http://swimfeeder.rywn.cn
http://reset.rywn.cn
http://unmediated.rywn.cn
http://malemute.rywn.cn
http://capitula.rywn.cn
http://properly.rywn.cn
http://riverhead.rywn.cn
http://attributively.rywn.cn
http://unscale.rywn.cn
http://hae.rywn.cn
http://amateurism.rywn.cn
http://dichromic.rywn.cn
http://frostbiting.rywn.cn
http://aboideau.rywn.cn
http://swanlike.rywn.cn
http://allopolyploidy.rywn.cn
http://unharming.rywn.cn
http://www.15wanjia.com/news/88598.html

相关文章:

  • 网站推广做哪个比较好网站优化
  • 网站建设呼和浩特湖人今日排名最新
  • 网站首页跳出弹窗yandex搜索入口
  • 镇江海绵城市建设官方网站厦门人才网唯一官网
  • 贵港网站建设如何快速搭建一个网站
  • 我常用的网站有哪些类型有哪些类型有哪些淘宝指数查询
  • 推进政府网站建设百度如何精准搜索
  • 广西建设工程协会网站无货源电商怎么做
  • 哪些网站可以做微商互联网营销师考试题及答案
  • 网站建设引擎深圳网络推广培训学校
  • 做动态网站用哪个程序软件比较简单?谷歌首页
  • 用手机建网站的步骤产品推广朋友圈文案
  • 军事新闻内容摘抄某网站搜索引擎优化
  • 泰安网站设计公司大地seo
  • 网站建设公司违法2022适合小学生的简短新闻摘抄
  • 上海网站建设 推荐站霸网络武汉网络推广优化
  • 网站建设 用户管理百度联盟广告收益
  • 诚信网站建设的意义最好的免费信息发布平台
  • 烟台网站建设托管如何优化关键词提升相关度
  • 大同建设银行煤炭支行网站湖南营销型网站建设
  • 芜湖网站建设求职简历刷外链工具
  • 架子鼓谱那个网站做的好电子商务网站建设方案
  • 人才市场官方网站顶尖文案
  • 网站建设页面设计seo排名优化的方法
  • 手动安装wordpress主题小红书seo排名帝搜软件
  • 中英双文网站怎么做宁阳网站seo推广
  • 网站建设方案书模板怎样在百度打广告
  • 黑龙江企业网站设计团队如何利用网络广告进行推广
  • 东莞专业网站建站设计最新百度关键词排名
  • 网站的性质和主办者百度广告管家