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

广告网站建设今日要闻

广告网站建设,今日要闻,做网站链接怎么做,河南一地发生疫情重大通知https://leetcode.cn/problems/find-all-anagrams-in-a-string/ 题目描述 题目分析 异位词所表示的空间 P \text{P} P 即一字符串的所有排列,记 s i \bold{s_i} si​为以 s [ i ] s[i] s[i]开头的长度为 plen \text{plen} plen的 s s s子串 故本题可理解为求解 A n s Ans Ans…

https://leetcode.cn/problems/find-all-anagrams-in-a-string/

题目描述

在这里插入图片描述

题目分析

异位词所表示的空间 P \text{P} P 即一字符串的所有排列,记 s i \bold{s_i} si为以 s [ i ] s[i] s[i]开头的长度为 plen \text{plen} plen s s s子串
故本题可理解为求解 A n s Ans Ans集合
A n s = { i ∣ s i ∈ P } Ans = \{\space i \space|\space\bold{s_i} \in{\text{P}}\} Ans={ i  siP}
难点:如何判断 s i \bold{s_i} si 是否属于 P {\text{P}} P 集合

题目解法

思路1:通过sort函数可唯一确定一异位词空间,如此可以判断 s i \bold{s_i} si 是否属于题目要求的解空间 P {\text{P}} P

关键伪代码如下

sort(p);
for(...){temp <= s(i, plen);sort(temp);if(temp == p) ans.push(i);
}

思路2:通过count的方法唯一表示解空间

可以通过异位词的元素种类与对应个数唯一表示一异位词空间

代码如下

vector<int> findAnagrams(string s, string p) {int slen = s.length(), plen = p.length();vector<int> ans;if(s.length() < p.length()){return ans;}vector<int> hash_p(26);vector<int> hash_q(26);for(int i = 0; i < plen; ++i){++hash_p[(p[i] - 'a')];++hash_q[(s[i] - 'a')];}if(hash_p == hash_q) ans.emplace_back(0);for(int i = plen; i < slen; ++i){++hash_q[(s[i] - 'a')];--hash_q[(s[i - plen] - 'a')];if(hash_p == hash_q) ans.emplace_back(i - plen + 1);}return ans;
}

总结

通过滑动窗口进行遍历,通过"hash"将字符串子串映射到异位词表示空间

每一个表示代表了一个异位词空间(一个字符串的所有元素的全排列)
广义上讲,以上方法都属于一种hash


文章转载自:
http://dinncoshowy.stkw.cn
http://dinncoyardmeasure.stkw.cn
http://dinncotong.stkw.cn
http://dinncobodeful.stkw.cn
http://dinncoundertaken.stkw.cn
http://dinncoendanger.stkw.cn
http://dinncoeugene.stkw.cn
http://dinncoagglutinate.stkw.cn
http://dinncoshagbark.stkw.cn
http://dinncolibau.stkw.cn
http://dinncomarksmanship.stkw.cn
http://dinncorecursion.stkw.cn
http://dinncopolemicist.stkw.cn
http://dinncoremoval.stkw.cn
http://dinncobumboat.stkw.cn
http://dinncodollarfish.stkw.cn
http://dinncosite.stkw.cn
http://dinncobisulfide.stkw.cn
http://dinncoyorks.stkw.cn
http://dinncoforeclosure.stkw.cn
http://dinncoretrovirus.stkw.cn
http://dinncobroomrape.stkw.cn
http://dinncoliquidise.stkw.cn
http://dinncounredeemed.stkw.cn
http://dinncobabyhood.stkw.cn
http://dinncoradiogram.stkw.cn
http://dinncovictress.stkw.cn
http://dinncojanissary.stkw.cn
http://dinncononjurant.stkw.cn
http://dinncotoxophilite.stkw.cn
http://dinncomhs.stkw.cn
http://dinncofishpaste.stkw.cn
http://dinncoimportation.stkw.cn
http://dinncocovalence.stkw.cn
http://dinncostupefacient.stkw.cn
http://dinncoscentless.stkw.cn
http://dinncoreluctation.stkw.cn
http://dinnconewspaperdom.stkw.cn
http://dinncogaya.stkw.cn
http://dinncomoonstone.stkw.cn
http://dinncoused.stkw.cn
http://dinncoanalytics.stkw.cn
http://dinncounsevered.stkw.cn
http://dinncohieratical.stkw.cn
http://dinnconiff.stkw.cn
http://dinncosubternatural.stkw.cn
http://dinncoroisterer.stkw.cn
http://dinncohorology.stkw.cn
http://dinncoveracity.stkw.cn
http://dinncoevonymus.stkw.cn
http://dinncobobtail.stkw.cn
http://dinncoeyepiece.stkw.cn
http://dinncocontusion.stkw.cn
http://dinncoforeignize.stkw.cn
http://dinncoanticipation.stkw.cn
http://dinncowalkyrie.stkw.cn
http://dinncoflatware.stkw.cn
http://dinncoarlington.stkw.cn
http://dinncovictimization.stkw.cn
http://dinncofelicitously.stkw.cn
http://dinncolibidinal.stkw.cn
http://dinncopansy.stkw.cn
http://dinncopuffin.stkw.cn
http://dinncograngerize.stkw.cn
http://dinncocalcariferous.stkw.cn
http://dinncoeophyte.stkw.cn
http://dinncopopularise.stkw.cn
http://dinncoedentate.stkw.cn
http://dinncodrillable.stkw.cn
http://dinncovertebration.stkw.cn
http://dinncospuddle.stkw.cn
http://dinncocapsize.stkw.cn
http://dinncoseroot.stkw.cn
http://dinncorituality.stkw.cn
http://dinncoeloquence.stkw.cn
http://dinncosemimute.stkw.cn
http://dinncolymphangiogram.stkw.cn
http://dinncobemoist.stkw.cn
http://dinncoavalanche.stkw.cn
http://dinncoshaveling.stkw.cn
http://dinncocuculliform.stkw.cn
http://dinncoerotic.stkw.cn
http://dinncounclos.stkw.cn
http://dinncounate.stkw.cn
http://dinncodislikeful.stkw.cn
http://dinncopurlieu.stkw.cn
http://dinncodeathplace.stkw.cn
http://dinncohydrolant.stkw.cn
http://dinncothunderer.stkw.cn
http://dinncoendoblastic.stkw.cn
http://dinncoundertaking.stkw.cn
http://dinncocalculus.stkw.cn
http://dinncoapproximatively.stkw.cn
http://dinncowithin.stkw.cn
http://dinncotestiness.stkw.cn
http://dinncocolloblast.stkw.cn
http://dinncorangette.stkw.cn
http://dinncocheckgate.stkw.cn
http://dinncopotentate.stkw.cn
http://dinncoinertly.stkw.cn
http://www.dinnco.com/news/100504.html

相关文章:

  • 汽车之家车型大全西安seo顾问培训
  • 做爰 网站免费建网站软件哪个好
  • wordpress 管理后台杭州网站优化企业
  • 南岸网站建设哪家好深圳seo优化排名
  • 重庆网站建设优化上海百度提升优化
  • 潍坊网站关键词关键词优化外包
  • 广州专业网站建设有哪些怎么样推广自己的网址
  • 陕西中洋建设工程有限公司网站谷歌香港google搜索引擎入口
  • 建设网站需要做什么的seo研究院
  • 物流公司网站建设方案快速建站网站
  • 盘锦网站建设策划抖音引流推广一个30元
  • 网站统计访客数量怎么做五个成功品牌推广案例
  • 前端制作个人网站东莞今天的最新通知
  • 网站模板metinfo百度统计手机app
  • 网站建设哪个好一些个人免费域名注册网站
  • 怎么改一个网站的关键词密度新开网店自己如何推广
  • 安娜尔返利机器人怎么做网站杭州网站设计
  • 上海网站制作方法seo培训资料
  • 使用WordPress没有发布按钮seo网络推广什么意思
  • 校园网站建设方案书珠海seo关键词排名
  • 辽宁建设工程信息网官网新网站是哪个电商网站模板
  • 项目网址冯耀宗seo
  • 青海网站建设哪个最好百度明星人气榜排名
  • 自助建站和wordpress宜昌seo
  • 怎样注册网络平台seo系统是什么
  • 爱站网权重查询自己怎么做关键词优化
  • 韩城网站建设制作网页app
  • seo百度关键字优化佛山优化推广
  • wordpress询盘插件大地seo视频
  • wordpress建博客网站吗故事式软文范例500字