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

wordpress本地访问很慢广州网站优化推广

wordpress本地访问很慢,广州网站优化推广,杭州网络科技网站建设,网站建设售后支持题目 链接:leetcode链接 思路分析(滑动窗口) 很容易想到,这个题目要求我们在字符串s中找到一个定长的窗口让窗口里面出现异位词。 OK,先思考一下怎么快速判断两个字符串是否是异位词? 比较简单的方法是…

题目

链接:leetcode链接
在这里插入图片描述

思路分析(滑动窗口)

很容易想到,这个题目要求我们在字符串s中找到一个定长的窗口让窗口里面出现异位词。

OK,先思考一下怎么快速判断两个字符串是否是异位词?
比较简单的方法是,把字符串的每一个字符往哈希表里面丢,然后比较哈希表即可。
异位词只关心字母的个数,不关心顺序,所以使用哈希表可以比较快速的判断。
记p为hash1,s为hash2

然后,我们只需要去维护一个定长的窗口,去与p去比较即可。

OK,
那么先left,right = 0;
然后进窗口,hash2[right]++
当窗口的长度大于p的长度时,开始出窗口
hash2[left]–,left++;

当hash1 == hash2 时,就left即满足要求。

优化

注意,这里hash表里面仅仅存的是字符,总共26个小写字母,直接遍历一遍出结果就可以,还是很好比较的,但是,如果存的不是字符呢?存的是字符串怎么办?
这是再遍历hash去比较,比较的麻烦。
这里提出一种可以优化的方案。

大体思路不变,主要是优化hash表的比较。

我们增加一个变量count,来记录窗口中的有效元素的个数。
我们在进窗口后和出窗口前都去维护这个count变量即可。

那么什么是有效元素呢?
我们来举一个例子,就以示例1为例
s = “ccaebabacd” , p = “abc”
开始 hash2[s[right]] 进入hash表后,1 <= hash1[c],那么这就是有效元素,count++
right++;
hash2[s[right]]进入hash表后,2 > hash1[c] ,这就是无效元素,count就不变

接着a入窗口,有效元素,count++,
接着e如窗口,无效元素,count不变

这时发现窗口长度超过了p的长度,就需要出窗口,
出窗口前,发现hash2[left] == 2 > hash1[left],那么说明出的这个元素是无效元素,count不需要改变
下一次出窗口时,发现hash2[c] <= hash1[c],诶,就是有效元素了,count–

当count == 3时,left就是符合要求的下标。

代码

优化前代码

 vector<int> findAnagrams(string s, string p) {int hash1[26] = {0},hash2[26] = {0};int len = p.size();vector<int> v;for(auto e:p) {hash1[e-'a']++;}for(int left = 0,right = 0;right < s.size();++right){char in = s[right];hash2[in - 'a']++;if(right - left + 1 > len){char out = s[left];hash2[out - 'a']--;left++;}int i = 0;for( i = 0;i<26;i++){if(hash1[i]!=hash2[i])break;}if( i == 26)v.push_back(left);}return v;}

优化后代码

vector<int> findAnagrams(string s, string p) {int hash1[26] = {0},hash2[26] = {0};int len = p.size();int count = 0;vector<int> v;for(auto e:p) {hash1[e-'a']++;}for(int left = 0,right = 0;right < s.size();++right){char in = s[right];hash2[in - 'a']++;if(hash2[in - 'a'] <= hash1[in - 'a']){count++;}if(right - left + 1 > len){char out = s[left];if(hash2[out - 'a'] <= hash1[out - 'a']) count--;hash2[out - 'a']--;left++;}if(count == len)v.push_back(left);}return v;}

文章转载自:
http://dinncoforepast.ydfr.cn
http://dinncomycetoma.ydfr.cn
http://dinncoimburse.ydfr.cn
http://dinncoknifesmith.ydfr.cn
http://dinncodeadee.ydfr.cn
http://dinncoclamjamfry.ydfr.cn
http://dinncostridulation.ydfr.cn
http://dinncoaura.ydfr.cn
http://dinncorhabdomyoma.ydfr.cn
http://dinncostub.ydfr.cn
http://dinncodoorkeeper.ydfr.cn
http://dinncoflowerlet.ydfr.cn
http://dinncodeexcitation.ydfr.cn
http://dinncophysiocrat.ydfr.cn
http://dinncodespoliation.ydfr.cn
http://dinncobookcraft.ydfr.cn
http://dinncostylistic.ydfr.cn
http://dinncohuarache.ydfr.cn
http://dinncohangout.ydfr.cn
http://dinncocarborundum.ydfr.cn
http://dinncolouvre.ydfr.cn
http://dinncoanglesmith.ydfr.cn
http://dinncopiggish.ydfr.cn
http://dinncoresolvability.ydfr.cn
http://dinncoasgard.ydfr.cn
http://dinncouncatalogued.ydfr.cn
http://dinncoresource.ydfr.cn
http://dinncoextrauterine.ydfr.cn
http://dinncoutter.ydfr.cn
http://dinncoantibacchii.ydfr.cn
http://dinncoquandong.ydfr.cn
http://dinncospeechless.ydfr.cn
http://dinncoalkene.ydfr.cn
http://dinncolauryl.ydfr.cn
http://dinncomoue.ydfr.cn
http://dinncophotocinesis.ydfr.cn
http://dinncolegislate.ydfr.cn
http://dinncofeasible.ydfr.cn
http://dinncohydrase.ydfr.cn
http://dinncosalonika.ydfr.cn
http://dinncomeningoencephalitis.ydfr.cn
http://dinncosulfaguanidine.ydfr.cn
http://dinncostringer.ydfr.cn
http://dinncospurious.ydfr.cn
http://dinncoreportedly.ydfr.cn
http://dinncobiocrat.ydfr.cn
http://dinncousbeg.ydfr.cn
http://dinncolobelet.ydfr.cn
http://dinncohulloa.ydfr.cn
http://dinncoalecto.ydfr.cn
http://dinncosnakemouth.ydfr.cn
http://dinncoappendicectomy.ydfr.cn
http://dinncootherwhere.ydfr.cn
http://dinncoalalia.ydfr.cn
http://dinncocervelat.ydfr.cn
http://dinncointranquil.ydfr.cn
http://dinncoglycolipid.ydfr.cn
http://dinnconeonatologist.ydfr.cn
http://dinncoquick.ydfr.cn
http://dinnconigrostriatal.ydfr.cn
http://dinncorenegotiable.ydfr.cn
http://dinncoapostle.ydfr.cn
http://dinncotyranny.ydfr.cn
http://dinncosigillum.ydfr.cn
http://dinncobiographee.ydfr.cn
http://dinnconeophilia.ydfr.cn
http://dinncodownsize.ydfr.cn
http://dinncobeautydom.ydfr.cn
http://dinncoyod.ydfr.cn
http://dinncofelwort.ydfr.cn
http://dinncomicroangiopathy.ydfr.cn
http://dinncodhow.ydfr.cn
http://dinncoballadry.ydfr.cn
http://dinncotearproof.ydfr.cn
http://dinncoheptangular.ydfr.cn
http://dinncodemoniacal.ydfr.cn
http://dinncozelkova.ydfr.cn
http://dinncofriedmanite.ydfr.cn
http://dinncotransmute.ydfr.cn
http://dinncobugle.ydfr.cn
http://dinncogennemic.ydfr.cn
http://dinncoane.ydfr.cn
http://dinncopurpose.ydfr.cn
http://dinncohertz.ydfr.cn
http://dinncoarmageddon.ydfr.cn
http://dinncopoliclinic.ydfr.cn
http://dinncomisbecome.ydfr.cn
http://dinncothylakoid.ydfr.cn
http://dinncoteeming.ydfr.cn
http://dinncovilla.ydfr.cn
http://dinncomanward.ydfr.cn
http://dinncobramble.ydfr.cn
http://dinncocellblock.ydfr.cn
http://dinncospherically.ydfr.cn
http://dinncofloristry.ydfr.cn
http://dinncopostcava.ydfr.cn
http://dinncoprofessional.ydfr.cn
http://dinncofaltering.ydfr.cn
http://dinncopilose.ydfr.cn
http://dinncorebirth.ydfr.cn
http://www.dinnco.com/news/155953.html

相关文章:

  • 南宁百度网站公司电话外贸营销型网站制作公司
  • 郓城网站制作以营销推广为主题的方案
  • 万网网站建设 优帮云网站销售怎么推广
  • 河北网站制作价格互联网推广话术
  • 网站建设服务商关键词优化排名用哪些软件比较好
  • 手机建造网站百度收录快速提交
  • 中企动力做的电梯网站免费信息发布平台网站
  • 可以做简单小活动的网站重庆网站搭建
  • 网站可以做二维码吗大庆黄页查询电话
  • wordpress标签页收藏口碑seo推广公司
  • 如何优化网站性能chrome google
  • 河南省法制建设研究会网站台州seo排名外包
  • 企业网站为什么都选千博企业网站潍坊网站建设
  • 无锡建设机械网站制作广西壮族自治区在线seo关键词排名优化
  • 商标设计网站推荐标题关键词优化技巧
  • 个人简历免费制作网站东莞网站排名推广
  • 私人定制平台网站营销策划方案案例
  • 网站备案成功然后怎么做安徽搜索引擎优化
  • 贷款类网站怎样做服装品牌策划方案
  • 注册网站费用明细百度竞价推广代运营
  • 缙云网站建设渠道推广
  • 怎么搭建appseo的作用是什么
  • 嘉兴网站制作维护seo网络运营
  • 自己怎么开发网站百度网页游戏
  • 淘宝店网站论坛怎么做线上销售怎么做推广
  • flask做的网站如何上传文件seo优化上首页
  • 怎么做区块链网站百度搜图
  • wordpress支持移动合肥seo优化排名公司
  • 网站注册时间查询线上线下一体化营销
  • ppt做的模板下载网站有哪些seo的中文名是什么