leetcode 日经贴,Cpp code -Minimum Window Substring
2015-05-24 17:21
465 查看
Minimum Window Substring
class Solution { public: string minWindow(string s, string t) { vector<int> count(256); int st = -1, ed = s.length(), distinct = 0; for (int i = 0; i < t.length(); ++i) { if (++count[t[i]] == 1) { ++distinct; } } int p1 = 0; int n = s.length(); for (int i = 0; i < n; ++i) { if (--count[s[i]] == 0) { --distinct; } if (distinct == 0) { while (p1 < i && count[s[p1]] < 0) { ++count[s[p1++]]; } if (i - p1 < ed - st) { st = p1; ed = i; } } } if (st == -1) { return ""; } return s.substr(st, ed - st + 1); } };
相关文章推荐
- leetCode_Minimum Window Substring
- Leetcode: Minimum window substring
- [leetcode] 76 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: 76. Minimum Window Substring
- [LeetCode] Minimum Window Substring
- LeetCode —— Minimum Window Substring
- Leetcode: Minimum Window Substring
- LeetCode76 Minimum Window Substring(两种解法)
- LeetCode 76 Minimum Window Substring
- leetcode- Minimum Window Substring
- [leetcode]Minimum Window Substring
- [LeetCode] Minimum Window Substring