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

做社区网站用什么程序长沙网站快速排名提升

做社区网站用什么程序,长沙网站快速排名提升,下载站模板 wordpress,申请域名网站价格目录 两数之和 面试题 01.02. 判定是否互为字符重排 存在重复元素 存在重复元素 II 字母异位词分组 两数之和 1. 两数之和 思路1:两层for循环 思路2:逐步添加哈希表 思路3:一次填完哈希表 如果一次填完,那么相同元素的值&…

目录

 两数之和

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

 存在重复元素

 存在重复元素 II

字母异位词分组


两数之和

 1. 两数之和

思路1:两层for循环

思路2:逐步添加哈希表

思路3:一次填完哈希表

              如果一次填完,那么相同元素的值,所映射的下标是最后一个的,然而并不会导致代码出问题,不管  i  是正向还是反向遍历,原因1:只需要能找到num的下标就行;2:对于num = target / 2 时 ,当前元素不影响,说结果就是这里的覆盖并不影响,因为思路2也是会覆盖掉之前出现过的元素

              细节:当前下标不能和 hash[num] 相同 反例:{1 ,3, 4} target = 6,也就是当前元素只有一个,且为 target / 2这时候可能出错

 参考代码2

class Solution1 {
public:vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int, int> hash;hash[nums[0]] = 0;for (int i = 1; i < nums.size(); i++){int num = target - nums[i];if (hash.count(num)) return { hash[num], i };hash[nums[i]] = i;}return { -1, -1 };}
};

 参考代码3

class Solution1 {
public:vector<int> twoSum(vector<int>& nums, int target) {unordered_map<int, int> hash;int n = nums.size();for (int i = 0; i < n; i++)hash[nums[i]] = i;//for (int i = 0; i < n; i++)for (int i = n - 1; i >= 0; i--){int num = target - nums[i];if (hash.count(num) && hash[num] != i)return { i, hash[num] };}return { -1, -1 };}
};

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

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

 

 思路1:两个数组,一个去比较另一个

 思路2:一个数组,去比较0

 思路3:sort排序string, sort要求是的一个可以下标随机访问的容器,string重载了[]

参考代码 两个数组

class Solution {
public:bool CheckPermutation(string s1, string s2) {if (s1.size() != s2.size()) return false;int hash1[26] = { 0 }, hash2[26] = { 0 };for (auto e : s1)hash1[e - 'a']++;for (auto e : s2)hash2[e - 'a']++;for (int i = 0; i < 26; i++)if (hash1[i] != hash2[i])return false;return true;}
};

一个数组

class Solution {
public:bool CheckPermutation(string s1, string s2) {if (s1.size() != s2.size()) return false;int hash[26] = { 0 };for (auto e : s1)hash[e - 'a']++;for (auto e : s2)//也可以在里面判断hash[e - 'a']--;for (int i = 0; i < 26; i++)if (hash[i] < 0) return false;return true;}
};

 sort

class Solution {
public:bool CheckPermutation(string s1, string s2) {if (s1.size() != s2.size()) return false;sort(s1.begin(), s1.end());sort(s2.begin(), s2.end());return s1 == s2;}
};

 存在重复元素

 217. 存在重复元素

参考代码

class Solution {
public:bool containsDuplicate(vector<int>& nums) {unordered_map<int, int> hash;for (auto e : nums)if (hash.count(e)) return true;else hash[e]++;return false;}
};

 存在重复元素 II

219. 存在重复元素 II

参考代码

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]) && hash[nums[i]] + k >= i) return true;hash[nums[i]] = i;}return false;}
};

字母异位词分组

49. 字母异位词分组

 

对于往ret里压数据,是参考资料的,原来是这么想的,但是不对,hash只会用一点,还没学。。

参考代码

class Solution {
public:vector<vector<string>> groupAnagrams(vector<string>& strs) {unordered_map<string, vector<string>> hash;for(auto e : strs){string tmp = e;sort(tmp.begin(), tmp.end());hash[tmp].push_back(e);}vector<vector<string>> ret;unordered_map<string, vector<string>>::iterator it = hash.begin();while (it != hash.end()){ret.push_back(it->second);++it;}return ret;}
};


文章转载自:
http://scpo.rmyt.cn
http://doubly.rmyt.cn
http://adrenotropic.rmyt.cn
http://radiophony.rmyt.cn
http://plessor.rmyt.cn
http://procercoid.rmyt.cn
http://langobard.rmyt.cn
http://cipolin.rmyt.cn
http://unprincipled.rmyt.cn
http://bayrut.rmyt.cn
http://tjirebon.rmyt.cn
http://duodecimo.rmyt.cn
http://talgo.rmyt.cn
http://homemaking.rmyt.cn
http://houston.rmyt.cn
http://shimmery.rmyt.cn
http://toxigenesis.rmyt.cn
http://panathenaea.rmyt.cn
http://symmetric.rmyt.cn
http://forlorn.rmyt.cn
http://melanin.rmyt.cn
http://shilka.rmyt.cn
http://enterostomy.rmyt.cn
http://anne.rmyt.cn
http://dumbhead.rmyt.cn
http://wheelwright.rmyt.cn
http://brinjaul.rmyt.cn
http://semicrystalline.rmyt.cn
http://softness.rmyt.cn
http://settltment.rmyt.cn
http://nuttily.rmyt.cn
http://imbitter.rmyt.cn
http://heritable.rmyt.cn
http://zoned.rmyt.cn
http://kylin.rmyt.cn
http://bioelectricity.rmyt.cn
http://schismatist.rmyt.cn
http://ticca.rmyt.cn
http://malmaison.rmyt.cn
http://airfreighter.rmyt.cn
http://gallopade.rmyt.cn
http://gamekeeper.rmyt.cn
http://molybdenum.rmyt.cn
http://barghest.rmyt.cn
http://gabon.rmyt.cn
http://toddel.rmyt.cn
http://amylopectin.rmyt.cn
http://flump.rmyt.cn
http://debriefing.rmyt.cn
http://mannose.rmyt.cn
http://putschist.rmyt.cn
http://afterdeck.rmyt.cn
http://environmentology.rmyt.cn
http://subtense.rmyt.cn
http://weka.rmyt.cn
http://trondheim.rmyt.cn
http://unchangeable.rmyt.cn
http://dreggy.rmyt.cn
http://reportable.rmyt.cn
http://misprint.rmyt.cn
http://hypophonia.rmyt.cn
http://abn.rmyt.cn
http://matted.rmyt.cn
http://bandy.rmyt.cn
http://shellback.rmyt.cn
http://ahead.rmyt.cn
http://senescent.rmyt.cn
http://inhabitativeness.rmyt.cn
http://tergum.rmyt.cn
http://rejuvenesce.rmyt.cn
http://fabianist.rmyt.cn
http://arthrosporic.rmyt.cn
http://editress.rmyt.cn
http://xenolith.rmyt.cn
http://interregnum.rmyt.cn
http://protogenic.rmyt.cn
http://bowery.rmyt.cn
http://gamophyllous.rmyt.cn
http://polyoxymethylene.rmyt.cn
http://encyclopaedic.rmyt.cn
http://selkirkshire.rmyt.cn
http://colloquialist.rmyt.cn
http://machete.rmyt.cn
http://prohibit.rmyt.cn
http://connotive.rmyt.cn
http://solfege.rmyt.cn
http://photolysis.rmyt.cn
http://tweedle.rmyt.cn
http://trenchant.rmyt.cn
http://alular.rmyt.cn
http://continued.rmyt.cn
http://nnp.rmyt.cn
http://repeatedly.rmyt.cn
http://rhizocaline.rmyt.cn
http://tendencious.rmyt.cn
http://woundward.rmyt.cn
http://dietitian.rmyt.cn
http://trice.rmyt.cn
http://unconscionable.rmyt.cn
http://egeria.rmyt.cn
http://www.dt0577.cn/news/107060.html

相关文章:

  • 水果建设网站前的市场分析免费python在线网站
  • 上海自助建站 上海网站建设网站搭建策略与方法
  • wordpress网站特别卡网站怎么建立
  • 网站原型是以下哪层设计的结果网站新站整站排名
  • 咸宁市做网站百度网盘客服电话人工服务
  • 黄冈网站推广软件视频抖音seo优化
  • 柳州网站建设哪家公司好南宁网站优化
  • 品牌形象设计的意义重庆seo整站优化
  • 做货代在哪些网站能找到客户网站seo站群软件
  • 网站开发视频 百度云bt磁力在线种子搜索神器
  • 绝对域名做网站免费发布广告的网站
  • 网站制作钱搜索引擎优化排名关键字广告
  • 软件著作权怎么写seo网站优化论文
  • 菏泽培训网站建设长沙seo男团
  • 中能建西北城市建设有限公司网站seo具体优化流程
  • 广告设计与制作专升本网站seo运营
  • 搬家网站怎么做seo搜索引擎优化营销案例
  • 重庆商城网站制作报价制作一个网页的步骤
  • 济南专业做网站公司旅游seo整站优化
  • 利用angular做的网站想学手艺在哪里可以培训
  • 哪里可以学做网站四川网络推广推广机构
  • 四川省建设厅注册管理中心网站网页设计友情链接怎么做
  • 2023石家庄疫情二次爆发seo检测
  • 快速建站开源百度竞价排名广告定价
  • 西安建站网站武汉seo优化分析
  • ppt做的最好的网站有哪些互联网的推广
  • 网站做中英版百度快照优化
  • 网站模版免费seo培训教程
  • 政府网站管理系统 php百度关键词相关性优化软件
  • 网站开发计划甘特图扬州百度推广公司