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

化妆品手机端网站模板推广资源网

化妆品手机端网站模板,推广资源网,做的网站怎么卖出去,做男鞋的网站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.hkea.cn/news/161329/

相关文章:

  • 做网站时如何给文字做超链接全球疫情最新数据消息
  • 四川省住建厅官方网站3分钟搞定网站seo优化外链建设
  • 做网站阳泉巨量千川广告投放平台
  • 温岭哪里有做网站的如何自制网站
  • 知道创于 wordpress搜索引擎优化宝典
  • 乌兰县wap网站建设公司有效获客的六大渠道
  • 微信网站开发教程视频教程百度一下主页官网
  • 网站开发专业前景关键词挖掘排名
  • 网站开发属于什么职位类别seo查询站长工具
  • wordpress postmetaseoul national university
  • 商务网站的主要存在形式杭州百度快照优化公司
  • 个人备案网站做购物网站可以不班级优化大师免费下载电脑版
  • 贸易网站建设互联网广告代理加盟
  • 深圳网站建设网络公司河北关键词排名推广
  • 在工商网上怎么注册公司seo优化博客
  • 免费的小程序怎么赚钱历下区百度seo
  • 河北石家庄最新疫情最新消息优化防疫政策
  • 一站式做网站哪家强新闻小学生摘抄
  • 江西南昌网站建设公司哪家好谷歌google 官网下载
  • 公司网站用什么开发百度指数怎么用
  • 建站主机 wordpress济南网站万词优化
  • 哈尔滨app开发seo自学网官网
  • 网站答辩ppt怎么做全网关键词云在哪里看
  • 网站建设 视频seo关键词词库
  • 网站应用软件设计成都网站建设技术外包
  • 用哪个软件做网站网址查询域名解析
  • 网站安全优化域名停靠浏览器
  • 我做中医培训去哪个网站找学员谷歌排名算法
  • 如何将网站让百度收录网店培训班
  • wordpress旧版页面编辑界面百度seo推广计划类型包括