{"id":167027,"date":"2020-10-06T03:13:44","date_gmt":"2020-10-05T19:13:44","guid":{"rendered":"http:\/\/4563.org\/?p=167027"},"modified":"2020-10-06T03:13:44","modified_gmt":"2020-10-05T19:13:44","slug":"facebook-%e9%9d%a2%e8%af%95%e9%a2%98%ef%bc%9a%e6%9c%80%e5%b0%8f%e5%ad%90%e4%b8%b2%e8%a6%86%e7%9b%96","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=167027","title":{"rendered":"Facebook \u9762\u8bd5\u9898\uff1a\u6700\u5c0f\u5b50\u4e32\u8986\u76d6"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Facebook \u9762\u8bd5\u9898\uff1a\u6700\u5c0f\u5b50\u4e32\u8986\u76d6               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 2<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u8bf4\u4e2a\u9898\u5916\u8bdd\uff0cH-1B \u6700\u4e25\u653f\u7b56\u51fa\u6765\u540e\uff0c\u6e7e\u533a\u5de5\u7a0b\u5e08\u8fd8\u6253\u7b97\u7559\u7f8e\u4e48\uff1f<\/p>\n<p>\u7ed9\u5b9a\u4e24\u4e2a\u5b57\u7b26\u4e32 source \u548c target. \u6c42 source \u4e2d\u6700\u77ed\u7684\u5305\u542b target \u4e2d\u6bcf\u4e00\u4e2a\u5b57\u7b26\u7684\u5b50\u4e32.<\/p>\n<ol>\n<li>\u5982\u679c\u6ca1\u6709\u7b54\u6848, \u8fd4\u56de &#8220;&#8221;.<\/li>\n<li>\u4fdd\u8bc1\u7b54\u6848\u662f\u552f\u4e00\u7684.<\/li>\n<li>target \u53ef\u80fd\u5305\u542b\u91cd\u590d\u7684\u5b57\u7b26, \u800c\u4f60\u7684\u7b54\u6848\u9700\u8981\u5305\u542b\u81f3\u5c11\u76f8\u540c\u6570\u91cf\u7684\u8be5\u5b57\u7b26.<\/li>\n<\/ol>\n<p>\u70b9\u6b64\u5728\u7ebf\u6d4b\u8bc4<\/p>\n<h2>\u6837\u4f8b 1:<\/h2>\n<pre><code>\u8f93\u5165: source = \"abc\", target = \"ac\" \u8f93\u51fa: \"abc\" <\/code><\/pre>\n<h2>\u6837\u4f8b 2:<\/h2>\n<pre><code>\u8f93\u5165: source = \"adobecodebanc\", target = \"abc\" \u8f93\u51fa: \"banc\" \u89e3\u91ca: \"banc\" \u662f source \u7684\u5305\u542b target \u7684\u6bcf\u4e00\u4e2a\u5b57\u7b26\u7684\u6700\u77ed\u7684\u5b50\u4e32. <\/code><\/pre>\n<h2>\u6837\u4f8b 3:<\/h2>\n<pre><code>\u8f93\u5165: source = \"abc\", target = \"aa\" \u8f93\u51fa: \"\" \u89e3\u91ca: \u6ca1\u6709\u5b50\u4e32\u5305\u542b\u4e24\u4e2a 'a'. <\/code><\/pre>\n<h2>\u89e3\u9898\u601d\u8def<\/h2>\n<ul>\n<li>\u672c\u9898\u91c7\u7528\u6ed1\u7a97\u6cd5\uff0c\u6ed1\u7a97\u6cd5\u662f\u53cc\u6307\u9488\u6280\u5de7\uff0c\u6307\u9488 left \u548c right \u5206\u522b\u6307\u5411\u7a97\u53e3\u4e24\u7aef\uff0c\u4ece\u5de6\u5411\u53f3\u6ed1\u52a8\uff0c\u5b9e\u65bd\u7ef4\u62a4\u8fd9\u4e2a\u7a97\u53e3\u3002\u6211\u4eec\u7684\u76ee\u6807\u662f\u627e\u5230 source \u4e2d\u6db5\u76d6 target \u5168\u90e8\u5b57\u6bcd\u7684\u6700\u5c0f\u7a97\u53e3\uff0c\u5373\u4e3a\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u3002<\/li>\n<\/ul>\n<h2>\u7b97\u6cd5\u6d41\u7a0b<\/h2>\n<ul>\n<li>\n<p>\u53d8\u91cf\u5b9a\u4e49\uff1a<\/p>\n<ul>\n<li>\u54c8\u5e0c\u8868 counter_s \u548c counter_t \u8868\u793a\u6570\u7ec4 source \u548c target \u4e2d\u6709\u6548\u5b57\u7b26\u7684\u51fa\u73b0\u6b21\u6570\uff0c\u5176\u4e2d\uff0c\u6211\u4eec\u5c06\u6709\u6548\u5b57\u7b26\u5b9a\u4e49\u4e3a target \u4e2d\u51fa\u73b0\u7684\u5b57\u7b26\u3002<\/li>\n<li>start \u662f\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u7684\u8d77\u59cb\u7d22\u5f15\uff0cminlen \u662f\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u7684\u957f\u5ea6\uff08\u4ece 0 \u8ba1\uff09\u3002<\/li>\n<li>valid \u8868\u793a source \u7684\u7a97\u53e3\u4e2d\u6ee1\u8db3 counter_t \u51fa\u73b0\u6b21\u6570\u8981\u6c42\u7684\u5b57\u7b26\u7684\u4e2a\u6570\u3002\u6ce8\u610f\uff0c\u76f8\u540c\u7684\u5b57\u7b26\u53ea\u8ba1\u7b97\u4e00\u6b21\u3002<\/li>\n<li>left \u548c right \u5206\u522b\u6307\u5411\u6ed1\u7a97\u4e24\u7aef\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u7b97\u6cd5\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li>\u521d\u59cb\u5316\uff1aleft \u6307\u9488\u548c right \u6307\u9488\u90fd\u6307\u5411 s[0]\u3002<\/li>\n<li>\u79fb\u52a8\u7a97\u53e3\u53f3\u8fb9\u754c\uff1a\u5c06 right \u6307\u9488\u53f3\u79fb\uff0c\u5982\u679c\u6307\u5411\u7684\u5b57\u7b26 ch \u662f\u6709\u6548\u5b57\u7b26\uff0c\u90a3\u4e48 counter_s[ch] += 1 \u3002\u5982\u679c\u5b57\u7b26 ch \u7684\u51fa\u73b0\u6b21\u6570\u8fbe\u6807\uff0c\u90a3\u4e48 valid += 1 \u3002<\/li>\n<li>\u5f53\u6211\u4eec\u5f97\u5230\u4e00\u4e2a\u53ef\u884c\u7a97\u53e3\uff0c\u5373\u5305\u542b target \u7684\u5168\u90e8\u5b57\u6bcd\u7684\u7a97\u53e3\u65f6:<\/li>\n<\/ol>\n<ul>\n<li>\u5224\u65ad\u6b64\u65f6\u7684\u5b50\u4e32\u662f\u5426\u957f\u5ea6\u66f4\u5c0f\u3002\u5982\u679c\u662f\uff0c\u66f4\u65b0\u5b50\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e start \u548c\u957f\u5ea6 minlen \u3002<\/li>\n<li>\u79fb\u52a8\u7a97\u53e3\u5de6\u8fb9\u754c\uff1a\u5c06 left \u53f3\u79fb\uff0c\u5982\u679c\u79bb\u5f00\u7684\u5b57\u7b26 left_ch \u662f\u6709\u6548\u5b57\u7b26\uff0c\u90a3\u4e48 counter_s[left_ch] -= 1 \u3002\u5982\u679c\u5b57\u7b26 left_ch \u7684\u51fa\u73b0\u6b21\u6570\u4e0d\u518d\u8fbe\u6807\uff0c\u90a3\u4e48 valid -= 1 \u3002<\/li>\n<li>\u5982\u679c\u7a97\u53e3\u4f9d\u7136\u53ef\u884c\uff0c\u5faa\u73af\u6b65\u9aa4 3 \u3002\u5426\u5219\uff0c\u8df3\u8f6c\u81f3\u6b65\u9aa4 2 \u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u590d\u6742\u5ea6\u5206\u6790\uff1a<\/h2>\n<ul>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\uff1aO(n)\uff0cn \u4e3a\u5b57\u7b26\u4e32 source \u7684\u957f\u5ea6\u3002<\/li>\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6\uff1aO(n)\u3002<\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code>public class Solution {     \/**      * @param source : A string      * @param target: A string      * @return: A string denote the minimum window, return \"\" if there is no such a string      *\/     public String minWindow(String source , String target) {         \/\/ \u521d\u59cb\u5316 counter_s \u548c counter_t         Map&lt;Character, Integer&gt; counter_t = new HashMap&lt;Character, Integer&gt;();         Map&lt;Character, Integer&gt; counter_s = new HashMap&lt;Character, Integer&gt;();         for (int i = 0; i &lt; target.length(); i++) {             int count = counter_t.getOrDefault(target.charAt(i), 0);             counter_t.put(target.charAt(i), count + 1);         }          int left = 0, valid = 0;         \/\/ \u8bb0\u5f55\u6700\u5c0f\u8986\u76d6\u5b50\u4e32\u7684\u8d77\u59cb\u7d22\u5f15\u53ca\u957f\u5ea6         int start = -1, minlen = Integer.MAX_VALUE;         for (int right = 0; right &lt; source.length(); right ++){             \/\/ \u79fb\u52a8\u53f3\u8fb9\u754c, ch \u662f\u5c06\u79fb\u5165\u7a97\u53e3\u7684\u5b57\u7b26             char ch = source.charAt(right);             if (counter_t.containsKey(ch)) {                 counter_s.put(ch, counter_s.getOrDefault(ch, 0) + 1);                 if (counter_s.get(ch).compareTo(counter_t.get(ch)) == 0) {                     valid++;                 }             }             \/\/ \u5224\u65ad\u5de6\u4fa7\u7a97\u53e3\u662f\u5426\u8981\u6536\u7f29             while (valid == counter_t.size()) {                 \/\/ \u66f4\u65b0\u6700\u5c0f\u8986\u76d6\u5b50\u4e32                 if (right - left &lt; minlen) {                     start = left;                     minlen = right - left;                 }             \/\/ left_ch \u662f\u5c06\u79fb\u51fa\u7a97\u53e3\u7684\u5b57\u7b26             char left_ch = source.charAt(left);             \/\/ \u5de6\u79fb\u7a97\u53e3             left ++;             \/\/ \u8fdb\u884c\u7a97\u53e3\u5185\u6570\u636e\u7684\u4e00\u7cfb\u5217\u66f4\u65b0             if (counter_t.containsKey(left_ch)) {                 if (counter_t.get(left_ch).equals(counter_s.get(left_ch))) {                         valid--;                 }                 counter_s.put(left_ch, counter_s.getOrDefault(left_ch, 0) - 1);             }         }     }     \/\/ \u8fd4\u56de\u6700\u5c0f\u8986\u76d6\u5b50\u4e32     return start == -1 ? \"\" : source.substring(start, start + minlen  + 1);     } } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Facebook \u9762\u8bd5\u9898\uff1a\u6700\u5c0f\u5b50\u4e32&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167027"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167027"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167027\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167027"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}