{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "fef93fc39e554ebaa5e936e8fa911855",
  "keywords": "哈希表,字符串,滑动窗口",
  "title": "最小覆盖子串",
  "desc": [
    {
      "content": "\n<p>给你一个字符串 <code>s</code> 、一个字符串 <code>t</code> 。返回 <code>s</code> 中涵盖 <code>t</code> 所有字符的最小子串。如果 <code>s</code> 中不存在涵盖 <code>t</code> 所有字符的子串，则返回空字符串 <code>\"\"</code> 。</p><p><strong>注意：</strong>如果 <code>s</code> 中存在这样的子串，我们保证它是唯一的答案。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>s = \"ADOBECODEBANC\", t = \"ABC\"<strong><br />输出：</strong>\"BANC\"</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>s = \"a\", t = \"a\"<strong><br />输出：</strong>\"a\"</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>1 <= s.length, t.length <= 10<sup>5</sup></code></li>\t<li><code>s</code> 和 <code>t</code> 由英文字母组成</li></ul><p> </p><strong>进阶：</strong>你能设计一个在 <code>o(n)</code> 时间内解决此问题的算法吗？",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tstring minWindow(string s, string t)\n\t{\n\t\tvector<int> count(128);\n\t\tfor (char c : t)\n\t\t{\n\t\t\tcount[c]++;\n\t\t}\n\t\tint l = 0, r = 0;\n\t\tint need_to_meet = t.length();\n\t\tint start, min_len = INT_MAX;\n\t\twhile (r < s.length())\n\t\t{\n\t\t\tif (--count[s[r++]] >= 0)\n\t\t\t{\n\t\t\t\tneed_to_meet--;\n\t\t\t}\n\t\t\twhile (need_to_meet == 0)\n\t\t\t{\n\t\t\t\tif (r - l < min_len)\n\t\t\t\t{\n\t\t\t\t\tstart = l;\n\t\t\t\t\tmin_len = r - l;\n\t\t\t\t}\n\t\t\t\tif (++count[s[l++]] > 0)\n\t\t\t\t{\n\t\t\t\t\tneed_to_meet++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn min_len == INT_MAX ? \"\" : s.substr(start, min_len);\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-614de2b516c846b88756982c0408dde8",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600471015"
}