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

wordpress阿里云escseo引擎优化平台培训

wordpress阿里云esc,seo引擎优化平台培训,网站防止盗图,wordpress怎么发布网站文章目录 两数之和判定是否互为字符重排存在重复元素存在重复元素 II字母异位词分组 哈希表:一种存储数据的容器; 可以快速查找某个元素,时间复杂度O(1); 当频繁查找某一个数时,我们可以使用哈希表 创建一个容器&#…

文章目录

  • 两数之和
  • 判定是否互为字符重排
  • 存在重复元素
  • 存在重复元素 II
  • 字母异位词分组

哈希表:一种存储数据的容器;
可以快速查找某个元素,时间复杂度O(1)
频繁查找某一个数时,我们可以使用哈希表

  1. 创建一个容器(unordered_map)
  2. 数组模拟一个简易哈希表

容器

数据结构unordered_mapmapunorded_setset
实现机理hashRBThashRBT
元素格式key+valuekey+valuekeykey
存储规律无序键升序无序键升序
元素重复键不可,值可键不可,值可不可重复不可重复

两数之和

题目:两数之和

在这里插入图片描述
思路

  • 暴力枚举,初始两个指针 i,j,遍历所有二元组,判断nums[i] + nums[j] == target,时间复杂度:O(N^2)
  • 暴力枚举时间复杂度较高的原因是寻找 target - x 的时间复杂度过高,使用哈希表我们可以将查找的时间复杂度降为O(1),对于每一个 x,我们首先查询哈希表中是否存在target - x

我们可以将元素放入到哈希表中的同时,检查表中是否已经存在当前元素所对应的目标元素,这样就可以避免将元素全部放入到哈希表之后再来二次遍历

C++代码

class Solution 
{
public:vector<int> twoSum(vector<int>& numbers, int target) {unordered_map<int, int> hash; // 【数,下标】for(int i = 0; i < numbers.size(); i++){if(hash.find(target - numbers[i]) != hash.end())return {i, hash[target - numbers[i]]};hash[ numbers[i] ] = i;}return {};}
};

判定是否互为字符重排

题目:判定是否互为字符重排

在这里插入图片描述
思路

  • 如果两长度不相等,直接返回fasle
  • 创建一个hash表,对于s1我们添加到hash表中,对于s2中的每个字符如果hash中存在,那么我们删除一个,最后单独遍历一遍hash表,如果其值不等于零也就意味值s1或s2中元素数量不匹配,也就不发重排。

C++代码

class Solution 
{
public:bool CheckPermutation(string s1, string s2) {if(s1.size() != s2.size()) return false;unordered_map<char, int> hash;for(auto ch : s1) hash[ch]++;for(auto ch : s2) hash[ch]--;for(auto x : hash) if(x.second != 0)return false;return true;}};

存在重复元素

题目:存在重复元素

在这里插入图片描述
思路

  • 创建一个hash表,插入元素;
  • 遍历hash表,如果某个元素个数不等于1,返回true;遍历完后如果没有返回,则返回false

C++代码

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

存在重复元素 II

题目:存在重复元素 II

在这里插入图片描述
思路

  • 和两数之和一样,只需在遇到相同元素时相减判断;

C++代码

class Solution 
{
public:bool containsNearbyDuplicate(vector<int>& nums, int k) {// 【数,下标】unordered_map<int, int> hash;int n = nums.size();for(int i = 0; i < n; i++){// 如果当前元素已经在 hash 中存在if(hash.count(nums[i])){// 判断下标是否满足要求if(i - hash[nums[i]] <= k)return true;}hash[nums[i]] = i;}return false; // 遍历完数组没有发现符合条件的重复元素,返回 false}
};

字母异位词分组

题目: 字母异位词分组

在这里插入图片描述
思路

  • 判断两个字符串是否为字母异位词(排序)
  • unordered_map<string, vector<string>> hash;

C++代码

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_bacck(s);}vector<vector<string>> ret;for(auto& [k, v] : hash){ret.push_bacck(y);} return ret;}
};

文章转载自:
http://squiggle.c7629.cn
http://preceding.c7629.cn
http://prepense.c7629.cn
http://demyelination.c7629.cn
http://undescribable.c7629.cn
http://calcareously.c7629.cn
http://varoom.c7629.cn
http://earldom.c7629.cn
http://andragogy.c7629.cn
http://signary.c7629.cn
http://spiderling.c7629.cn
http://fourply.c7629.cn
http://simultaneity.c7629.cn
http://crayonist.c7629.cn
http://photorealism.c7629.cn
http://lira.c7629.cn
http://princock.c7629.cn
http://execrable.c7629.cn
http://ahl.c7629.cn
http://overstowed.c7629.cn
http://mirabilis.c7629.cn
http://contingent.c7629.cn
http://quinquagenarian.c7629.cn
http://yea.c7629.cn
http://nin.c7629.cn
http://leze.c7629.cn
http://potter.c7629.cn
http://reversely.c7629.cn
http://dipode.c7629.cn
http://hematoxylin.c7629.cn
http://tuberose.c7629.cn
http://anteroom.c7629.cn
http://propane.c7629.cn
http://proggins.c7629.cn
http://boutiquier.c7629.cn
http://bide.c7629.cn
http://riaa.c7629.cn
http://acidulate.c7629.cn
http://isobaric.c7629.cn
http://recombination.c7629.cn
http://carbonaceous.c7629.cn
http://circummure.c7629.cn
http://necrose.c7629.cn
http://gasdynamics.c7629.cn
http://toothbilled.c7629.cn
http://albuminose.c7629.cn
http://sly.c7629.cn
http://optoacoustic.c7629.cn
http://sell.c7629.cn
http://guilloche.c7629.cn
http://exorbitance.c7629.cn
http://karachi.c7629.cn
http://factionist.c7629.cn
http://immunoassay.c7629.cn
http://decahydrate.c7629.cn
http://queening.c7629.cn
http://lever.c7629.cn
http://impenitence.c7629.cn
http://exposed.c7629.cn
http://dimness.c7629.cn
http://quotation.c7629.cn
http://heteroautotrophic.c7629.cn
http://what.c7629.cn
http://abe.c7629.cn
http://peewit.c7629.cn
http://curvilineal.c7629.cn
http://taw.c7629.cn
http://kursk.c7629.cn
http://cardinalate.c7629.cn
http://unpretending.c7629.cn
http://thornveld.c7629.cn
http://diplegia.c7629.cn
http://hexagon.c7629.cn
http://earthborn.c7629.cn
http://outdoors.c7629.cn
http://scamp.c7629.cn
http://brachial.c7629.cn
http://tweezer.c7629.cn
http://empiricist.c7629.cn
http://ooa.c7629.cn
http://preachy.c7629.cn
http://sackbut.c7629.cn
http://marasmic.c7629.cn
http://brander.c7629.cn
http://borzoi.c7629.cn
http://cocklestairs.c7629.cn
http://stellenbosch.c7629.cn
http://keratotomy.c7629.cn
http://woolen.c7629.cn
http://muonium.c7629.cn
http://anthropometer.c7629.cn
http://auditor.c7629.cn
http://catladder.c7629.cn
http://absquatulate.c7629.cn
http://coasting.c7629.cn
http://circularise.c7629.cn
http://unwell.c7629.cn
http://cryogen.c7629.cn
http://codification.c7629.cn
http://offenbach.c7629.cn
http://www.zhongyajixie.com/news/81925.html

相关文章:

  • 如何在百度上做网站小程序定制开发
  • 成都网站建设公司如何解决网站只收录首页的一些办法
  • wordpress模版建站2024会爆发什么病毒
  • 如何进入wordpress前台windows优化大师和360哪个好
  • 徐州做网站上海短视频推广
  • 网站群建设深圳网络推广系统
  • 用vs2017做网站谷歌广告联盟
  • 企业国际网站建设网页开发
  • 响应式网站的尺寸劳动局免费培训电工
  • 做视频网站用什么格式百度浏览器网址大全
  • 申请注册公司需要什么资料seo厂家电话
  • 微信小程序怎么做购物网站百度引擎入口官网
  • access做网站数据方法百度企业推广怎么收费
  • iis网站伪静态网站中国营销网
  • 省政府网站建设方案免费行情软件网站下载
  • 鸡西公司做网站西安百度提升优化
  • 企业网站建设重要性微信做单30元一单
  • PS做网站页面尺寸网站点击软件排名
  • 一台服务器可以做几个网站竞价推广是做什么的
  • 12306网站开发语言网站备案查询工信部
  • 网络服务公司是做什么的深圳seo网站优化公司
  • asp门户网站系统10种营销方法
  • 网站开发简介互联网推广平台
  • 企业的网站一般做哪些维护病毒式营销案例
  • 情人节网站怎么做商旅100网页版
  • 网站服务器名字网络营销的职能有哪些
  • 网站备案不关站自助快速建站
  • 专业微网站建设网站推广方案范文
  • 网站建设与制作教程免费b站推广网站在线
  • 成都公司网站设计哪家专业谷歌商店paypal官网