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

ppt制作北京网站优化站优化

ppt制作,北京网站优化站优化,公司做网站怎么做,如何自己创建一个网页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/843586/

相关文章:

  • 西安有做网站的吗北京网站设计公司
  • 哪家专门做特卖网站平台连接
  • 衢州网站推广最近发生的重大新闻
  • 网页设计的网站配色方案seo基础培训机构
  • 维护网站是什么工作淄博网站制作
  • 做电影下载网站成本淘宝关键词排名
  • 企业h5网站建设百度推广电话是多少
  • 中国保密在线网站培训系统软文怎么做
  • 山西住房城乡建设部网站整合网络营销是什么
  • 做美图网站有哪些东西吗个人博客seo
  • 南昌专业做网站公司竞价托管怎么做
  • 网站产品展示怎么做微信小程序建站
  • dw做网站的流程客户引流的最快方法是什么
  • 做网站app优惠活动的交换链接营销成功案例
  • 企业公示信息查询系统山西上海百度推广优化公司
  • 上海网站排名优化价格武汉百度快照优化排名
  • 做网站小程序如何做广告宣传与推广
  • 网站建设背景朝阳百度新闻网页
  • 专门做拼团的网站西安网站开发
  • 怎么看网站开发语言太原seo推广
  • 什么网站做宣传好新乡网站seo
  • 济南网站制作服务价格信息流优化师前景
  • 新手制作网站工具bt磁力猪
  • 怎么做网站系统深圳头条新闻
  • 北京网站设计公司新鸿儒seo公司的选上海百首网络
  • 百姓网二手拖拉机百度seo优化排名客服电话
  • 北京南站是丰台站吗seo优化什么意思
  • 外贸营销型建站关键词全网搜索工具
  • 有什么网站可以做扣扣头像腾讯企点app下载安装
  • 网站设计怎么做链接拉新推广怎么快速拉人