Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string minWindow(string s, string t) {
- int sindex = 0, tindex = 0, slen = s.length(), tlen = t.length(), start = -1, len = slen;
- while(sindex < slen) {
- if(s[sindex] == t[tindex]) {
- if(++tindex == tlen) {
- //check feasibility from left to right of T
- int end = sindex+1;
- //check optimization from right to left of T
- while(--tindex >= 0) {
- while(s[sindex--] != t[tindex]);
- }
- ++sindex;
- ++tindex;
- //record the current smallest candidate
- if(end - sindex < len) {
- len = end - sindex;
- start = sindex;
- }
- }
- }
- ++sindex;
- }
- return (start == -1) ? "" : s.substr(start, len);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement