LeetCode OJ Minimum Window Substring
来源:互联网 发布:王良正射鱼器淘宝 编辑:程序博客网 时间:2024/06/09 22:48
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).
For example,
S = "ADOBECODEBANC"
T = "ABC"
Minimum window is "BANC"
.
Note:
If there is no such window in S that covers all characters in T, return the emtpy string ""
.
If there are multiple such windows, you are guaranteed that there will always be only one unique minimum window in S.
char *minWindow(char *S, char *T) {int SL = strlen(S), TL = strlen(T);bool inT['z' + 1] = { false };int num['z' + 1] = { 0 };for (int i = 0; i < TL; i++) num[T[i]] += inT[T[i]] = true;int ps1 = 0, ps2 = -1, ansP = 0, ansL = SL + 1;while (ps2 < SL)if (!TL) {if (ansL > ps2 - ps1 + 1) ansL = ps2 + 1 - (ansP = ps1);if (inT[S[ps1]] && ++num[S[ps1]] > 0) TL++;ps1++;} else if (--num[S[++ps2]] >= 0 && inT[S[ps2]]) TL--;if ((S + ansP)[ansL]) (S + ansP)[ansL] = '\0';return ansL == SL + 1 ? "" : S + ansP;}
0 0
- LeetCode OJ:Minimum Window Substring
- LeetCode OJ - Minimum Window Substring
- LeetCode OJ 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
- (6)设计模式:工厂模式
- python中的高等函数初探
- 写在今天的开车教训
- 关于前端的一点思考
- 使用storyboard创建导航控制器以及控制器的生命周期
- LeetCode OJ Minimum Window Substring
- iOS容易造成循环引用的三种场景,就在你我身边!
- 黑马程序员—OC学习笔记—OOP中一个类包含另外一个类的对象
- Object-C中的NSString
- cocos2d-x随机数的产生
- Android入门:隐式Intent
- BCB ServerSocket多线程示例
- CH3: 列表
- BNUOJ 13268 Aladdin and the Optimal Invitation