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

做企业平台的网站有哪些西安网站制作建设

做企业平台的网站有哪些,西安网站制作建设,汽车网站 源码,恶搞app制作软件Problem: 76. 最小覆盖子串 文章目录 题目描述思路复杂度Code 题目描述 思路 1.定义两个map集合need和window(以字符作为键,对应字符出现的个数作为值),将子串t存入need中; 2.定义左右指针left、right均指向0&#xff…

Problem: 76. 最小覆盖子串

文章目录

  • 题目描述
  • 思路
  • 复杂度
  • Code

题目描述

在这里插入图片描述在这里插入图片描述

思路

1.定义两个map集合need和window(以字符作为键,对应字符出现的个数作为值),将子串t存入need中;
2.定义左右指针left、right均指向0(形成窗口),定义int类型变量len记录最小窗口长度,valid记录当前窗口否存最短子串中的字符个数
3.向右扩大窗口,遍历到到的字符c如果在need中时,window[c]++,同时如果window[c] == need[c],则valid++
4.如果valid == need.size(),则表示可以开始收缩窗口,并更新最小窗口禅读(如果移除的字符在need中,同时window[d] == need[d],则valid–,window[d]–);

复杂度

时间复杂度:

O ( n ) O(n) O(n);其中 n n n为字符串 s s s的长度

空间复杂度:

O ( n ) O(n) O(n)

Code

class Solution {
public:/*** Two pointer** @param s Given string* @param t Given string* @return string*/string minWindow(string s, string t) {unordered_map<char, int> need;unordered_map<char, int> window;for (char c: t) {need[c]++;}int left = 0;int right = 0;int valid = 0;// Records the starting index and length of the minimum overlay substringint start = 0;int len = INT_MAX;while (right < s.size()) {//c is the character moved into the windowchar c = s[right];// Move the window rightright++;// Perform some column updates to the data in the windowif (need.count(c)) {window[c]++;if (window[c] == need[c]) {valid++;}}// Determine whether to shrink the left windowwhile (valid == need.size()) {// Update the minimum overlay substringif (right - left < len) {start = left;len = right - left;}//d is the character to be moved out of the windowchar d = s[left];// Move the window leftleft++;// Perform some column updates to the data in the windowif (need.count(d)) {if (window[d] == need[d]) {valid--;}window[d]--;}}}// Returns the minimum overlay substringreturn len == INT_MAX ? "" : s.substr(start, len);}
};
http://www.khdw.cn/news/16764.html

相关文章:

  • 深圳微商城网站制作深圳网络推广外包公司
  • 一个人网站运营怎么做网店代运营公司靠谱吗
  • 天眼查企业信息查询平台官网石家庄全网seo
  • 免费 网站源码网站seo招聘
  • 西安做网站需要多少钱商品关键词举例
  • 如何做好商务网站的运营怎么做北京疫情最新数据
  • 建立网站的申请什么是全网营销推广
  • 深圳外贸网站建设公司河南网站优化公司哪家好
  • 在手机上编程的软件seo品牌
  • 网站建设深圳公司哪家好seo网站查询工具
  • 一般做海报的图片跟哪个网站下载百度网盘客服24小时电话人工服务
  • 网页制作的公司排名重庆网站排名优化教程
  • 如何做网站吸引广告商全网营销推广案例
  • 网站制作主题思路武汉seo公司哪家专业
  • 做美女网站犯法吗推广普通话
  • php本地建站工具百度信息流广告怎么收费
  • 备案网站容易被收录长尾关键词挖掘
  • 武汉网站建设设计哪家好产品软文撰写
  • 网站怎么做滚动字幕培训机构学校
  • 做网站知识点企业自建网站
  • 衡水做企业网站的价格哪家公司建设网站好
  • 哪家网站开发好网站建设网站定制
  • 网络营销是什么的基础武汉seo服务多少钱
  • 推荐做微商海报的网站重庆网站seo好不好
  • 集团公司网站源码php免费域名解析平台
  • 微信小程序h5开发东莞网站关键词优化公司
  • 商务网站建设推广渠道怎么写
  • python做网站 jsp百度网盘下载慢怎么解决
  • 做网站用源码微信营销
  • 律师网站建设哪家专业有人百度看片吗