当前位置:网站首页>Minimum covering substring of two pointers
Minimum covering substring of two pointers
2022-06-30 14:37:00 【Douglas_ LT】
A daily topic ing, Today is a day hard topic 76. Minimum Window Substring
class Solution {
public:
string minWindow(string s, string t) {
vector <int> num(128,0);
vector <bool> flag(128,false);
for(int i=0;i<t.length();i++){
flag[t[i]]=true;
num[t[i]]++;
}
bool fflag=true;
int l=0,min_l=0,min_size=s.length()+1,cnt=0;
for(int i=0;i<s.length();i++){
if(flag[s[i]]){
fflag=false;
num[s[i]]--;
if(num[s[i]]>=0){
cnt++;
}
while(cnt==t.length()){
if(i-l+1<min_size){
min_size=i-l+1;
min_l=l;
}
if(flag[s[l]]&&++num[s[l]]>0){
cnt--;
}
l++;
}
}
}
if(min_size<t.length()||min_size>s.length()||fflag){
return "";
}
return s.substr(min_l,min_size);
}
};
边栏推荐
- Component communication mode
- PHP excel export function encapsulation (based on phpexcel class)
- Laravel8 custom log directory, rename
- Google Earth engine (GEE) -- converts string to number and applies it to time search (ee.date.fromymd)
- PHP 2D array change key name
- JS array sorting method summary
- Dart extended feature
- notepad正则删除关键词所在行
- [buuctf] [actf2020 freshman competition]include
- V3 01_ Welcome
猜你喜欢

Summary of use of laravel DCAT admin

Crypto questions

Detailed explanation of the first three passes of upload Labs

Error on datetime when importing SQL file from MySQL

About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)

Google Earth engine (GEE) - ghsl: global human settlements layer, built grid 1975-1990-2000-2015 (p2016) data set

Laravel configures passport and returns token using JWT

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

Laravel upload error

XSS challenge (1-5) more detailed answers
随机推荐
Experiment 2: stack
Initial attack and defense world Misc
Realize a simple LAN communication (similar to feiqiu)
org.json.JSONObject对象转json,json新增元素,根据json的key获取值。以及list对象格式字符串转jsonArray
V3_ Chrome extended Chinese translation document V3 directory
Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
PHP recursive multi-level classification, infinite classification
ThinkPHP v3.2 comment annotation injection write shell
Upgrade centos7 mysql5.5 to mysql5.7 non RPM in the form of tar package
PHP common authentication / third-party methods
Dart extended feature
Go sync. WaitGroup
【BUUCTF】 EasySql
Getting started with shell Basics
Impersonate server and client using message queuing
Error $(...) size is not a function
JS array sorting method summary
V3 01_ Welcome
2021-05-12
Thoughts on the security of a PHP file name regular verification