Minimum Window Substring
来源:互联网 发布:淘宝 拍摄脸部 编辑:程序博客网 时间:2024/05/29 16:42
class Solution {public: string minWindow(string s, string t) { if(t.empty()||s.empty()||s.size() < t.size()) return ""; int p1 = 0, p2 = 0; int count = t.size(); int limit = s.size(); int pos = -1, length = limit + 1; map<char, int> mapCount; for(auto i : t) //记录T中每个 char 出现的次数 mapCount[i]++; while(p2 < limit){ if (mapCount[s[p2]] > 0) --count; --mapCount[s[p2]]; //减少所需要T中字符串的个数 ++p2; // p2 移到包含所有 t 的位置,p1开始 缩减 while (count == 0){ if (p2 - p1 < length){ length = p2 - p1; pos = p1; } if (mapCount[s[p1]] == 0) ++count; //说明当前串已经包含所有 S[p2]字符 ++mapCount[s[p1]];//增加所需要T中字符串的个数 ++p1; } } if(pos < 0) return ""; return s.substr(pos,length); }};
0 0
- LeetCode: Minimum Window Substring
- LeetCode Minimum Window Substring
- LeetCode : Minimum Window Substring
- [LeetCode] Minimum Window Substring
- [Leetcode] Minimum Window Substring
- Minimum Window Substring
- LeetCode: Minimum Window Substring
- Minimum Window Substring
- [LeetCode]Minimum Window Substring
- Minimum Window Substring
- Minimum Window Substring
- [leetcode]Minimum Window Substring
- Minimum Window Substring
- Leetcode:Minimum Window Substring
- LeetCode-Minimum Window Substring
- [leetcode] Minimum Window Substring
- [leetcode] Minimum Window Substring
- leetcode Minimum Window Substring
- 53. Maximum Subarray
- Java研发方向如何准备BAT技术面试
- Excel插入图表失真(数据格式原因)修复笔记
- Spring boot 和 mybatis 学习笔记1--框架整合
- 字体控制
- Minimum Window Substring
- Android Camera开发之基础知识篇
- DP Codeforces Round 401#div2 E.Hanoi Factory
- 半年总结
- MFC在命令行窗口输出
- Unity 通过LineRenderer绘制两点之间的直线
- 《写给大家看的设计书》总结
- Android Studio设置自动导包
- 实现开发环境、测试环境、生产环境配置自动切换