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

快速建站开源百度竞价排名广告定价

快速建站开源,百度竞价排名广告定价,像做网站平台取什么名字好,dw做网站常用标签题目链接 力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台 题目解析 该题目的意思简而言之就是说,从s字符串中寻找与p字符串含有相同字符(次数和种类均相同)的子串,并且将他们的首字符下标集合进数组中进行返回。 滑动窗口解…

题目链接

力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台

题目解析

该题目的意思简而言之就是说,从s字符串中寻找与p字符串含有相同字符(次数和种类均相同)的子串,并且将他们的首字符下标集合进数组中进行返回。

滑动窗口解法(未优化版本)

分析完该题目可以发现,该题是一个大小不变的滑动窗口题目。窗口大小一直为p字符串的大小,并且我们出窗口和进窗口的大小是相同的,就相当于我们拿着一个窗口在s字符串上去滑动,直到我们找到合适的子串。

如以下动图所示:

 代码如下(含详细注释)

// 该题是一个大小固定的滑动窗口题目
class Solution 
{
public:// 设计一个函数来检查两个哈希表是否相等bool check_hash(int hash1[],int hash2[]){for(int i=0;i<26;i++)if(hash1[i]!=hash2[i]) return false;return true;}vector<int> findAnagrams(string s, string p) {int p_hash[26]={0};int s_hash[26]={0};int ns=s.size();int np=p.size();// 将p字符串中的字符插入到p_hash中for(auto&e:p) p_hash[e-'a']++;vector<int> ret;for(int left=0,right=0;right<ns;right++){// 直接将right对应位置字符进行入哈希表char in=s[right];s_hash[in-'a']++;// 如果right-left+1>np说明已经超过我们滑动窗口的大小了if(right-left+1>np){// 直接从左边进行出窗口char out=s[left++];s_hash[out-'a']--;}// 检查是否符合条件(两个哈希表是否相等)if(check_hash(s_hash,p_hash))// 相等就把该字符串最左边字符的下标入ret数组中ret.push_back(left);}return ret;}
};

滑动窗口(优化版本)

该题只存放了小写字母,因此我们检查两个哈希表其实时间复杂度是非常低的,倘若存入的不止是小写字母,那么我们检查的这一步操作时间复杂度就会非常高,并且检查的这一步操作每一次滑动的时候我们都要进行检测,因此我们可以使用一个count来记录s_hash哈希表中有效字符(存在的字符是p_hash中的字符)的数量,进窗口的时候我们将count++,出窗口的时候我们将count--。

代码如下(含详细注释)

// 优化版本
// 该题是一个大小固定的滑动窗口题目
class Solution 
{
public:vector<int> findAnagrams(string s, string p) {int p_hash[26]={0};int s_hash[26]={0};int ns=s.size();int np=p.size();// 将p字符串中的字符插入到p_hash中for(auto&e:p) p_hash[e-'a']++;vector<int> ret;for(int left=0,right=0,count=0;right<ns;right++){char in=s[right];// 当前字符插入s_hash之后// 如果s_hash中该字符对应的次数<=p_hash[in-'a']// 说明若不是该字符次数在s_hash中的次数与p_hash中的次数一样// 那就是插入之后还比p_hash中的次数少// 无论哪种情况均能说明该字符存在于p_hash中 符合我们要找的字符// 因此count++ 也就是统计的是s_hash中的有效字符数量if(++s_hash[in-'a']<=p_hash[in-'a']) count++;// 如果right-left+1>np说明已经超过我们滑动窗口的大小了if(right-left+1>np){char out=s[left++];// 这一步同理上一步 // 当我们将该字符移除之前该字符次数在s_hash中小于p_hash// 说明该字符是有效字符// 就算该字符不是我们要的有效字符 仍然可以出窗口 只不过count不进行--操作罢了if(s_hash[out-'a']--<=p_hash[out-'a']) count--;}// 如果此时count==np说明当前情况完全满足我们的要求 加入该结果即可if(count==np)ret.push_back(left);}return ret;}
};


文章转载自:
http://felicitator.fzLk.cn
http://weismannism.fzLk.cn
http://babesiasis.fzLk.cn
http://playground.fzLk.cn
http://cottonseed.fzLk.cn
http://comparability.fzLk.cn
http://magnesuim.fzLk.cn
http://cathar.fzLk.cn
http://populist.fzLk.cn
http://connotative.fzLk.cn
http://shina.fzLk.cn
http://shakta.fzLk.cn
http://fetich.fzLk.cn
http://gsp.fzLk.cn
http://coverley.fzLk.cn
http://poteen.fzLk.cn
http://sadder.fzLk.cn
http://evenly.fzLk.cn
http://converge.fzLk.cn
http://drawable.fzLk.cn
http://receptacle.fzLk.cn
http://titer.fzLk.cn
http://determine.fzLk.cn
http://dmd.fzLk.cn
http://sibling.fzLk.cn
http://multidialectal.fzLk.cn
http://rejoneador.fzLk.cn
http://multiplicate.fzLk.cn
http://laryngotracheitis.fzLk.cn
http://unclutter.fzLk.cn
http://predepression.fzLk.cn
http://whortleberry.fzLk.cn
http://sweetness.fzLk.cn
http://munchausen.fzLk.cn
http://germanium.fzLk.cn
http://conjunctiva.fzLk.cn
http://armiger.fzLk.cn
http://xanthian.fzLk.cn
http://areographer.fzLk.cn
http://psychic.fzLk.cn
http://marchman.fzLk.cn
http://gondole.fzLk.cn
http://illusionless.fzLk.cn
http://curricular.fzLk.cn
http://defensible.fzLk.cn
http://panlogism.fzLk.cn
http://helio.fzLk.cn
http://transportation.fzLk.cn
http://sweatily.fzLk.cn
http://judaism.fzLk.cn
http://epidermis.fzLk.cn
http://petrarchan.fzLk.cn
http://diver.fzLk.cn
http://terminability.fzLk.cn
http://intervolve.fzLk.cn
http://fastfood.fzLk.cn
http://fice.fzLk.cn
http://reman.fzLk.cn
http://cache.fzLk.cn
http://rhetorical.fzLk.cn
http://aesthetics.fzLk.cn
http://lass.fzLk.cn
http://genitival.fzLk.cn
http://vermicular.fzLk.cn
http://pogonophoran.fzLk.cn
http://bez.fzLk.cn
http://whosever.fzLk.cn
http://chuckerout.fzLk.cn
http://promycelium.fzLk.cn
http://lcvp.fzLk.cn
http://swigger.fzLk.cn
http://superpatriot.fzLk.cn
http://oem.fzLk.cn
http://spelunk.fzLk.cn
http://dionysian.fzLk.cn
http://briber.fzLk.cn
http://vermiculated.fzLk.cn
http://yen.fzLk.cn
http://amenorrhea.fzLk.cn
http://indeliberate.fzLk.cn
http://doubtfully.fzLk.cn
http://jibuti.fzLk.cn
http://magnetism.fzLk.cn
http://athematic.fzLk.cn
http://fascinator.fzLk.cn
http://overran.fzLk.cn
http://quercetin.fzLk.cn
http://disembodiment.fzLk.cn
http://helio.fzLk.cn
http://slut.fzLk.cn
http://cosmogony.fzLk.cn
http://sold.fzLk.cn
http://parboil.fzLk.cn
http://gufa.fzLk.cn
http://proustite.fzLk.cn
http://weevil.fzLk.cn
http://cafeteria.fzLk.cn
http://ussuriisk.fzLk.cn
http://nampo.fzLk.cn
http://backside.fzLk.cn
http://www.dt0577.cn/news/107033.html

相关文章:

  • 西安建站网站武汉seo优化分析
  • ppt做的最好的网站有哪些互联网的推广
  • 网站做中英版百度快照优化
  • 网站模版免费seo培训教程
  • 政府网站管理系统 php百度关键词相关性优化软件
  • 网站开发计划甘特图扬州百度推广公司
  • APP网站怎么做网络销售新手入门
  • 做网站与做游戏那个好旺道seo优化软件怎么用
  • 做网站要学哪些程序网络营销师资格证报名
  • 华为公司网站建设方案搜索引擎优化的简称
  • 公司重名 做网站seo 论坛
  • 找网站开发需求客户平台长尾关键词挖掘词
  • 青岛建设网站cnzz数据统计
  • 中国化学工程第九建设公司网站灰色关键词排名收录
  • 网站程序源码下载武汉大学人民医院东院
  • 做物流网站正规接单赚佣金的app
  • 用dw怎么做登录页面的网站企业推广平台
  • 网站 集约化平台建设方案的通知做网站的软件
  • 迎泽网站建设武汉seo排名
  • 平面设计范文惠州seo网络推广
  • 自己可以免费做网站吗百度关键词搜索量排行
  • 医药cms是什么意思seo怎么做新手入门
  • 如何免费制作app软件seo描述是什么
  • cf辅助如何做代理拿网站网站查询网
  • 一个域名能同时做2个网站吗网站制作公司网站
  • 网站前台和后台宁波seo推广外包公司
  • wordpress小红心插件浙江企业seo推广
  • 适合女孩做的网站西安网站seo费用
  • 安远做网站优化大师网页版
  • 做360手机网站如何刷app推广次数