题目:biubiu 题意:在字符串中找到最小的覆盖单词的子串,覆盖要求含有单词的全部字符。 通过滑动窗口实现。移动右指针找到符合条件的子串,移动左指针来使最小。
#include #include #include #include #include #include #include #include using namespace std; class Solution { public: unordered_mapori, cnt; bool check() { for (const auto& p : ori) { if (cnt[p.first] < p.second) return false; } return true; } string minWindow(string s, string t) { for (const auto& c : t) { ori[c]++; } int l = 0, r = -1; int len = INT_MAX, ansL = -1, ansR = -1; //cout << s.size() << endl; while (r > word1 >> word2) { Solution s; cout << s.minWindow(word1, word2) << endl; } return 0; }
上一篇 docker 部署 geoserver
下一篇 C语言:求序列前N项和
版权所有 (c)2021-2022 MSHXW.COM
ICP备案号:晋ICP备2021003244-6号