[Leetcode]Minimum Window Substring
来源:互联网 发布:医疗器械专用软件 编辑:程序博客网 时间:2024/06/10 21:41
class Solution {
public:
string minWindow(string s, string t) {
vector<int> found(128,0);
vector<int> needfound(128,0);
for(int i=0;i<t.size();i++)
needfound[t[i]]++;
found[s[0]]++;
int count=t.size();
if(found[s[0]]<=needfound[s[0]])
count--;
int result=INT_MAX;
int end=0;int begin=0;int len;
int minbegin,minlen;
while(true)
{
if(count==0)
{
while(found[s[begin]]>needfound[s[begin]])
{
found[s[begin]]--;
begin++;
}
len=end-begin+1;
if(len<result)
{
minbegin=begin;
result=len;
}
}
if(end<s.size())
{
end++;
found[s[end]]++;
if(found[s[end]]<=needfound[s[end]])
count--;
}
else
break;
}
if(result!=INT_MAX)
return s.substr(minbegin,result);
else
return "";
}
};
public:
string minWindow(string s, string t) {
vector<int> found(128,0);
vector<int> needfound(128,0);
for(int i=0;i<t.size();i++)
needfound[t[i]]++;
found[s[0]]++;
int count=t.size();
if(found[s[0]]<=needfound[s[0]])
count--;
int result=INT_MAX;
int end=0;int begin=0;int len;
int minbegin,minlen;
while(true)
{
if(count==0)
{
while(found[s[begin]]>needfound[s[begin]])
{
found[s[begin]]--;
begin++;
}
len=end-begin+1;
if(len<result)
{
minbegin=begin;
result=len;
}
}
if(end<s.size())
{
end++;
found[s[end]]++;
if(found[s[end]]<=needfound[s[end]])
count--;
}
else
break;
}
if(result!=INT_MAX)
return s.substr(minbegin,result);
else
return "";
}
};
0 0
- LeetCode: Minimum Window Substring
- LeetCode Minimum Window Substring
- LeetCode : Minimum Window Substring
- [LeetCode] Minimum Window Substring
- [Leetcode] Minimum Window Substring
- LeetCode: Minimum Window Substring
- [LeetCode]Minimum Window Substring
- [leetcode]Minimum Window Substring
- Leetcode:Minimum Window Substring
- LeetCode-Minimum Window Substring
- [leetcode] Minimum Window Substring
- [leetcode] Minimum Window Substring
- leetcode Minimum Window Substring
- [LeetCode] Minimum Window Substring
- [LeetCode] Minimum Window Substring
- leetcode minimum window substring
- LeetCode - Minimum Window Substring
- LeetCode:Minimum Window Substring
- Linux(android) 磁盘及分区基础知识
- lvs 负载均衡fullnat 模式clientip 怎样传递给 realserver
- 2015.07.15-编译stm32-soft在初始化BOOT任务时挂死(KEIL)
- android5.0使用requestWindowFeature(Window.FEATURE_NO_TITLE)隐藏标题栏的报错的解决方法
- 深入学习请求响应(三)---request的应用
- [Leetcode]Minimum Window Substring
- 【Open】内存MAP需要通过配置文件生成
- 【程序员创业】商业计划书怎么写才能与众不同?
- Zookeeper入门实验——安装配置
- zookeeper原理(转)
- C#设计模式(1)单例模式
- 【Leetcode】Course Schedule II #210
- 【Linux探索之旅】第一部分第四课:磁盘分区,并完成Ubuntu安装
- C#设计模式(2)简单工厂模式