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

一家做特卖的网站叫什么电商平台怎么做

一家做特卖的网站叫什么,电商平台怎么做,基于站点的推广,局域网中怎么访问自己做的网站一、哈希表剖析 1、哈希表底层:通过对C的学习,我们知道STL中哈希表底层是用的链地址法封装的开散列。 2、哈希表作用:存储数据的容器,插入、删除、搜索的时间复杂度都是O(1),无序。 3、什么时…

一、哈希表剖析

1、哈希表底层:通过对C++的学习,我们知道STL中哈希表底层是用的链地址法封装的开散列

2、哈希表作用:存储数据的容器,插入、删除、搜索的时间复杂度都是O(1),无序。

3、什么时候使用哈希表:需要频繁查找数据的场景。

4、OJ中如何使用哈希表???

(1)STL中的容器(适用所有场景,比如字符串相关、数据映射下标)

(2)数组模拟简易哈希表(减小时间损耗,容器的封装有一定代价)—>大多以下两种情况适用

情况1:(char)涉及到字符串中的“字符” ,hash[26]可以映射所有的字母。

情况2:(int)数据范围较小的时候

二、两数之和

. - 力扣(LeetCode)

解法2代码: 

class Solution {
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){int x=target-nums[i];if(hash.count(x)) return {hash[x],i};hash[nums[i]]=i;}return {-1,-1};}
};

 三、判定是否互为字符重排

. - 力扣(LeetCode)

 解法2代码:

class Solution {
public:bool CheckPermutation(string s1, string s2) {//小优化if(s1.size()!=s2.size()) return false;//用哈希表int hash[26]={0};for(char&ch:s1) ++hash[ch-'a'];//检测第二个数组for(char&ch:s2)  if(--hash[ch-'a']<0)  return false;return true;}
};

四、存在重复元素I

. - 力扣(LeetCode)

解法2代码:

class Solution {
public:bool containsDuplicate(vector<int>& nums) {unordered_set<int> hash; //有负数,所以必须用库里面的哈希表for(auto&e:nums) if(hash.count(e)) return true;else hash.insert(e);return false;}
};

 五、存在重复元素II

. - 力扣(LeetCode)

解法1代码:

class Solution {
public:bool containsNearbyDuplicate(vector<int>& nums, int k) {unordered_map<int,size_t> hash;//数值和下标的映射size_t n=nums.size();for(size_t i=0;i<n;++i){//如果哈希表中有这个数if(hash.count(nums[i])&&i-hash[nums[i]]<=k) return true;hash[nums[i]]=i;//存下标的映射}return false;}
};

解法2代码:

class Solution {
public:bool containsNearbyDuplicate(vector<int>& nums, int k) {//滑动窗口解题,让set始终保存着k个元素,如果发现了区间内有重复元素,那么就可以返回trueunordered_set<int> s;size_t n=nums.size();for(size_t i=0;i<n;++i){if(s.count(nums[i])) return true;s.emplace(nums[i]);//不断将数字丢进去if(i>=k) s.erase(nums[i-k]); //窗口超出区间了,就将最前面那个给删掉}return false;}
};

六、存在重复元素III(经典)

. - 力扣(LeetCode)

 解法1代码:

class Solution {
public://绝对值尽量拆解掉//滑动窗口解决问题(控制区间)  需要支持插入、查找、删除  尽可能有序 set//k是下标的差值  t是元素的差值bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {//lower_bound 利用二分找到第一个>=num的迭代器 降序就是<=//upper_bound 利用二分找到第一个>num的迭代器  降序就是<set<long> s;//需要一个有序集合for(size_t i=0;i<nums.size();++i){ //在下标范围为 [max(0,i−k),i] 内找到值范围在 [u−t,u+t]的数。set<long>::iterator it=s.lower_bound((long)nums[i]-t);if(it!=s.end()&&*it<=(long)nums[i]+t) return true;s.insert(nums[i]);if(i>=k)  s.erase(nums[i - k]);}return false;}
};

 思路2:分桶(非常精巧的思路)

思路来源:. - 力扣(LeetCode)分桶思路详细讲解

     因为这个思路来源写得非常的详细,所以直接看就行,以往我们的分桶,更多的是针对整数的分桶,但是在该题中,扩展了存在负数的时候如何分桶,保证每个桶内的元素个数是一样的。这是一种非常巧妙的方法!!!要结合具体的实例去看!!

核心思路:保证每个桶内的绝对值相差小于t,k个桶。当我们遍历到这个数的时候,如果对应的桶的存在,就是true,如果相邻桶存在,看看差值是否符合要求。每个桶中只会有一个元素,因为有多的我们就会直接返回结果。

class Solution {
public:int getid(long u,long t){return u>=0?u/(t+1):(u+1)/(t+1)-1;}bool containsNearbyAlmostDuplicate(vector<int>& nums, int k, int t) {//桶排序   size_t n=nums.size();//分成k个桶  每个桶的大小是t+1 (0,1,2,3) ->保证一个桶里面是符合的unordered_map<int,int> hash;  //第一个是存id  第二个是存元素for(size_t i=0;i<n;++i){long u=nums[i];int id= getid(u,t); //找编号//看看当前桶存不存在if(hash.count(id)) return true;//看看相邻桶在不在,如果在的话 就看看差值if(  hash.count(id-1)&&u-hash[id-1]<=t||hash.count(id+1)&&hash[id+1]-u<=t) return true;if(i>=k) hash.erase(getid(nums[i-k],t));//桶数多了,就去掉一个hash[id]=u;//开新的桶}return false;}
};

七、字母异位词分组(经典)

. - 力扣(LeetCode)

class Solution {
public:vector<vector<string>> groupAnagrams(vector<string>& strs) {//字母异位词->排序后都是相同的unordered_map<string,vector<string>> hash; //将异位词绑定起来for(auto&s:strs){string temp=s;sort(temp.begin(),temp.end());hash[temp].emplace_back(s);}//提取出来vector<vector<string>> ret;for(auto&[x,y]:hash)  ret.emplace_back(y); //取哈希表中键值对的方法C++14支持//for(auto&kv:hash)  ret.push_back(kv.second);return ret;}
};

八、前K个高频单词(经典)

 . - 力扣(LeetCode)

解法1:map+vector+稳定排序+lambda优化
          map的底层是红黑树,插入的时候map<string,int> 会按照字典序排好,而我们现在要按照出现次序去排序,同时对于出现次数相同的保证字典序在前面,所以我们其中之一的策略就是vector+sort ,但是sort底层是快排,并不具备稳定性,但是库里面有一个stable_sort是稳定的排序

class Solution {
public:typedef pair<string,int> PSI;vector<string> topKFrequent(vector<string>& words, int k) {map<string,int> countmap;//计数for(auto&s:words) ++countmap[s];//此时已经按照字典序排好了,将其拷贝到vector中vector<PSI> nums(countmap.begin(),countmap.end());//要用一个稳定的排序 我们排序的是比较value,所以要修改比较逻辑stable_sort(nums.begin(),nums.end(),[](const PSI&kv1,const PSI&kv2) {return kv1.second>kv2.second;});vector<string> ret(k);for(int i=0;i<k;++i)  ret[i]=nums[i].first;return ret;}
};

解法2:unordered_map+vector+sort+调整比较逻辑+lambda优化 

class Solution {
public:typedef pair<string,int> PSI;vector<string> topKFrequent(vector<string>& words, int k) {unordered_map<string,int> countmap;//计数for(auto&s:words) ++countmap[s];//此时已经按照字典序排好了,将其拷贝到vector中vector<PSI> nums(countmap.begin(),countmap.end());//要用一个稳定的排序 我们排序的是比较value,所以要修改比较逻辑sort(nums.begin(),nums.end(),[](const PSI&kv1,const PSI&kv2){ return kv1.second>kv2.second||(kv1.second==kv2.second&&kv1.first<kv2.first);});vector<string> ret(k);for(int i=0;i<k;++i)  ret[i]=nums[i].first;return ret;}
};

上面两种解法都是借助vector容器+sort去解决的。

 解法3:unordered_map+priority_queue+compare类

class Solution {
public:typedef pair<string,int> PSI;struct compare//要注意仿函数要+const修饰,否则可能编译不过{bool operator()(const PSI&kv1,const PSI&kv2) const{if(kv1.second==kv2.second) return kv1.first<kv2.first;return kv1.second>kv2.second;}};vector<string> topKFrequent(vector<string>& words, int k) {unordered_map<string,int> countmap;//计数for(auto&s:words) ++countmap[s];//丢到优先级队列里priority_queue<PSI,vector<PSI>,compare> heap;for (auto& it : countmap) {heap.push(it);if (heap.size() > k) heap.pop();}vector<string> ret(k);for(int i=k-1;i>=0;--i) {ret[i]=heap.top().first;heap.pop();}return ret;}
};

 解法4:unordered_map+multiset+compare类

class Solution {
public:typedef pair<string,int> PSI;struct compare//要注意仿函数要+const修饰,否则可能编译不过{bool operator()(const PSI&kv1,const PSI&kv2) const{return kv1.second>kv2.second||(kv1.second==kv2.second&&kv1.first<kv2.first);}};vector<string> topKFrequent(vector<string>& words, int k) {unordered_map<string,int> countmap;//计数for(auto&s:words) ++countmap[s];multiset<PSI,compare> sortmap(countmap.begin(),countmap.end());vector<string> ret(k);multiset<PSI,compare>::iterator it=sortmap.begin();size_t i=0;while(k--) {ret[i++]=it->first;++it;}return ret;}
};

 解法5:map+multimap+compare类(能过 但这是巧合)

       这题能过的原因是map实现了字典序的排序。而底层的multimap封装中对于相同的键值是优先插入到其右侧。

class Solution {
public:struct compare//要注意仿函数要+const修饰,否则可能编译不过{bool operator()(const int&k1,const int&k2) const{return k1>k2;}};vector<string> topKFrequent(vector<string>& words, int k) {map<string,int> countmap;//计数for(auto&s:words) ++countmap[s];multimap<int,string,compare> sortmap;for(auto &kv:countmap) sortmap.insert(make_pair(kv.second,kv.first));vector<string> ret(k);auto it=sortmap.begin();size_t i=0;while(k--) {ret[i++]=it->second;++it;}return ret;}
};


文章转载自:
http://wanjiahemorrhoids.sqxr.cn
http://wanjiagristly.sqxr.cn
http://wanjiaincurrent.sqxr.cn
http://wanjiamascaron.sqxr.cn
http://wanjiasitology.sqxr.cn
http://wanjiaendoproct.sqxr.cn
http://wanjiasteamtight.sqxr.cn
http://wanjiawearer.sqxr.cn
http://wanjiaantagonist.sqxr.cn
http://wanjiasewin.sqxr.cn
http://wanjiabreathe.sqxr.cn
http://wanjiaramulose.sqxr.cn
http://wanjiaadjective.sqxr.cn
http://wanjiayechy.sqxr.cn
http://wanjiasolifluxion.sqxr.cn
http://wanjiaphototimer.sqxr.cn
http://wanjiawitchwoman.sqxr.cn
http://wanjiaperhaps.sqxr.cn
http://wanjiakerman.sqxr.cn
http://wanjiacradling.sqxr.cn
http://wanjianightstool.sqxr.cn
http://wanjiacorydaline.sqxr.cn
http://wanjiahexameral.sqxr.cn
http://wanjiadioptase.sqxr.cn
http://wanjiaurgent.sqxr.cn
http://wanjiapockety.sqxr.cn
http://wanjiarnase.sqxr.cn
http://wanjiacpc.sqxr.cn
http://wanjiadepute.sqxr.cn
http://wanjiavalued.sqxr.cn
http://wanjiabowman.sqxr.cn
http://wanjiafinalize.sqxr.cn
http://wanjiasubsternal.sqxr.cn
http://wanjiapasteurellosis.sqxr.cn
http://wanjiafeatheriness.sqxr.cn
http://wanjiagreensward.sqxr.cn
http://wanjiabarometer.sqxr.cn
http://wanjiapirimicarb.sqxr.cn
http://wanjiavaulting.sqxr.cn
http://wanjiaribband.sqxr.cn
http://wanjiaclamant.sqxr.cn
http://wanjiacomptroller.sqxr.cn
http://wanjiaamber.sqxr.cn
http://wanjiaperjurer.sqxr.cn
http://wanjiacyathiform.sqxr.cn
http://wanjianudibranch.sqxr.cn
http://wanjiasupertanker.sqxr.cn
http://wanjiaha.sqxr.cn
http://wanjiaatactic.sqxr.cn
http://wanjiaprelude.sqxr.cn
http://wanjiahemimorphic.sqxr.cn
http://wanjiaspermatology.sqxr.cn
http://wanjiathomist.sqxr.cn
http://wanjiamill.sqxr.cn
http://wanjiaderisory.sqxr.cn
http://wanjiaepiphyllous.sqxr.cn
http://wanjiaishmael.sqxr.cn
http://wanjiatacitly.sqxr.cn
http://wanjiademonomancy.sqxr.cn
http://wanjiabaconian.sqxr.cn
http://wanjiadamselfly.sqxr.cn
http://wanjiacytogenetical.sqxr.cn
http://wanjialychnis.sqxr.cn
http://wanjiagerminable.sqxr.cn
http://wanjiatullibee.sqxr.cn
http://wanjiaphagocytic.sqxr.cn
http://wanjiakeynesian.sqxr.cn
http://wanjiamodal.sqxr.cn
http://wanjiaacquiescence.sqxr.cn
http://wanjiaphoneticist.sqxr.cn
http://wanjiaitching.sqxr.cn
http://wanjiastorekeeper.sqxr.cn
http://wanjiabravery.sqxr.cn
http://wanjiasesamin.sqxr.cn
http://wanjiaequipollence.sqxr.cn
http://wanjiaveined.sqxr.cn
http://wanjiaaga.sqxr.cn
http://wanjiafactually.sqxr.cn
http://wanjianonliterate.sqxr.cn
http://wanjiaenswathement.sqxr.cn
http://www.15wanjia.com/news/116394.html

相关文章:

  • 充实网站 廉政建设 板块能搜任何网站的浏览器
  • 免抵退税在哪个网站做31省市新增疫情最新消息
  • 腾讯云可以做网站吗3网络营销招聘岗位有哪些
  • 域名停靠网站下载大全网站在线客服系统免费
  • 制作网站首页psd搜外网友情链接
  • 西安网络公司做网站云速seo百度点击
  • 电影网站开发毕业论文百度广告位价格表
  • 网站开发 海淀百度首页官网
  • 商河便宜做网站的公司软文是什么意思通俗点
  • 不花钱做推广的网站深圳seo优化seo优化
  • flash网站系统seo黑帽技术
  • 有哪个网站可以做口腔执业助理医师题库今天新闻头条
  • 番禺高端网站建设免费的个人主页网页制作网站
  • 商城网站制作推广团队
  • 开网站做淘宝客优化怎么做
  • 自己创建网站怎么得流量钱周口网络推广公司
  • wordpress 多梦东莞seo整站优化
  • 聊城正规网站建设设计公司前端优化
  • 大庆市建设大厦网站攀枝花seo
  • 深圳罗湖企业网站推广百度seo算法
  • wordpress和wamp佛山网站优化排名推广
  • 普洱网站建设网站seo什么意思
  • 网页设计教程文字和图片日照seo优化
  • 怎么在百度做网站抖音seo怎么收费
  • 中国互联网协会靠谱吗seo排名外包
  • 聊城做网站网络公司外链是什么意思
  • 用别人公司名字做网站违法么seo搜索优化是什么意思
  • 有哪些做ppt网站云资源软文发布平台
  • 软件系统设计石家庄网站seo外包
  • wordpress变身插件网站seo关键词