leetcode 76: Minimum Window Substring
2015-08-05 21:03
477 查看
class Solution { public: string minWindow(string s, string t) { int slen=s.length(); int tlen=t.length(); int need[128]={INT_MIN}; for(int i=0;i<tlen;i++) need[t[i]]=need[t[i]]==INT_MIN?1:need[t[i]]+1; int start=0,end=0,count=0,min_len=INT_MAX,min_idx=0; for(;end<slen;end++) { if(need[s[end]]>0)//needed by t { need[s[end]]--; count++; } else if(need[s[end]]!=INT_MIN)needed but the number is enough need[s[end]]--; if(count==tlen) { while(need[s[start]]<0)//find the non-redundant start { if(need[s[start]]!=INT_MIN) ++need[s[start++]]; else start++; } if(end-start+1<min_len)//update the min { min_len=end-start+1; min_idx=start; } need[s[start]]++; start++; count--; } } return min_len==INT_MAX?"":s.substr(min_idx,min_len); } };
相关文章推荐
- shell字符串截取操作
- LeetCode(12)Integer to Roman
- C/C++经典算法精华整理(4)-位字段输出二进制数据
- Android 4.4 Graphic Architecture
- mybatis 多对多映射关系
- LeetCode(12)Integer to Roman
- java中的包以及内部类的介绍
- Rescue
- Python文档中if __name__ == '__main__'
- Search in Rotated Sorted Array(leetcode)
- myeclipse中的SpringMVC项目创建(引入velocity框架)
- property 中的strong 与weak
- 我知道点redis-数据结构与对象(链表)
- 虚拟机字节码执行引擎
- HDOJ 5352 MZL's City 匈牙利匹配
- iOS开发---轮播图模块(连续循环滚动版)
- JAVA基础篇二(Java,C++中的面向对象)
- android学习连接网页
- 【ci框架】ci框架授课思路
- C/C++经典算法精华整理(3)-实现栈的数据结构