当前位置:网站首页>727. Minimum window subsequence sliding window
727. Minimum window subsequence sliding window
2022-07-23 09:11:00 【Empress Yu】
727. Minimum window subsequence
Given string
SandT, findSThe shortest one in ( continuity ) SubstringW, bringTyesWOf Subsequence .If
SNo window in can containTAll characters in , Returns an empty string"". If there is more than one window with the shortest length , Return to the one on the left of the starting position .Example 1:
Input : S = "abcdebdde", T = "bde" Output :"bcde" explain : "bcde" Yes, the answer , Because it's in a string of the same length "bdde" Before appearance . "deb" Not a shorter answer , Because it must appear in order in the window T The elements in .notes :
- All input strings contain only lowercase letters .All the strings in the input will only contain lowercase letters.
SThe length range is[1, 20000].TThe length range is[1, 100].
The result of doing the question
success , Barely write it out with a sliding window
Method : The sliding window
1. Determine starting point , Those that do not match the first character will be skipped
2. Make a perfect match , If you can complete the matching , Then add to the answer
class Solution {
public String minWindow(String s1, String s2) {
int m = s1.length();
int n = s2.length();
int ans = 0;
int start = 0;
for(int i =0 ; i < m-n+1; i++){
while (i<m&&s1.charAt(i)!=s2.charAt(0)) ++i;
int j = i;
int k = 0;
for(; j < m&&k<n; j++){
if (s1.charAt(j)==s2.charAt(k)){
++k;
}
}
if(k==n&&(j-i<ans||ans==0)){
ans = j-i;
start = i;
}
}
return s1.substring(start,start+ans);
}
}边栏推荐
- 7. Image data processing of paddlepaddle
- 【CANN训练营】学习笔记——Diffusion和GAN对比,Dalle2和Parti
- NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
- Template school jumpserver security operation and maintenance audit screen
- 【并发编程】第二章:从核心源码深入ReentrantLock锁
- go语言中的结构体和组合思想入门示例
- 【微信小程序】开发入门篇(二)
- 基于JSP实现OA办公系统
- SQL Server 数据库设计--SELECT语句之二
- -Bash: wget: command not found
猜你喜欢
随机推荐
Print prime numbers between 100 and 200
BGP experiment
[Huawei online battle service] how can new players make up frames when the client quits reconnection or enters the game halfway?
UGUI源码解析——IClippable
How many of the 50 classic computer network interview questions can you answer? (III)
解析steam与创客教育课堂的统筹规划
跨境电商旺季来临,汇付国际收款0费率助你赢战旺季!
SPSS Chi-Square
发现了一个好用到爆的数据分析利器
Mathematical modeling interpolation fitting
在线抠图和换背景及擦除工具
数学建模——图与网络模型及方法(二)
【华为联机对战服务】客户端退出重连或中途进入游戏,新玩家如何补帧?
Internet download manager is simply a killer of downloaders
小白股票开户安全吗?网上可以办理吗?
[cann training camp] learning notes - Comparison between diffusion and Gan, dalle2 and Party
【管理篇 / 升级】* 02. 查看升级路径 * FortiGate 防火墙
Day3 POC and exp learning Pikachu brute force cracking with token
UGUI源码解析——IMaskable
IDM下载器免费高质量的Win下载工具无使用限制









