{"id":187568,"date":"2020-11-07T18:21:33","date_gmt":"2020-11-07T10:21:33","guid":{"rendered":"http:\/\/4563.org\/?p=187568"},"modified":"2020-11-07T18:21:33","modified_gmt":"2020-11-07T10:21:33","slug":"%e9%bb%91%e8%bd%a6%e9%9d%a2%e7%bb%8f%ef%bc%9a%e5%ad%97%e6%a8%a1%e5%bc%8f-ii","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187568","title":{"rendered":"\u9ed1\u8f66\u9762\u7ecf\uff1a\u5b57\u6a21\u5f0f II"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u9ed1\u8f66\u9762\u7ecf\uff1a\u5b57\u6a21\u5f0f II               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zzzrf <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5317\u7f8e\u516c\u53f8\uff1aUber<\/p>\n<p>\u81ea\u4ece Uber \u4e0a\u5e02\u66b4\u96f7\u540e\uff0c\u4e0d\u77e5\u9053\u8fd8\u6709\u591a\u5c11\u4eba\u60f3\u53bb Uber \uff1f<\/p>\n<p>\u79d1\u666e\u4e00\u4e0b\uff0cUber \u7684\u9762\u8bd5\u6d41\u7a0b\uff08\u793e\u62db\uff09\u5927\u81f4\u662f\uff1a 5 \u8f6e VO\uff0c\u4e24\u8f6e coding\uff0c\u4e00\u8f6e\u7cfb\u7edf\u8bbe\u8ba1\uff0c\u4e00\u8f6e hiring manager\uff0c\u4e00\u8f6e bar raiser \u3002<\/p>\n<p>\u4e0d\u8fc7 Uber \u7684\u9898\u5e93\u5f88\u5927\uff0c\u57fa\u672c\u6ca1\u6709\u91cd\u590d\u7684\u9898\u3002<\/p>\n<p>\u8fd9\u9053\u9898\uff0c\u611f\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u7ec3\u7ec3\u624b\u3002<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a pattern \u548c\u4e00\u4e2a\u5b57\u7b26\u4e32 str\uff0c\u67e5\u627e str \u662f\u5426\u9075\u5faa\u76f8\u540c\u7684\u6a21\u5f0f\u3002<\/p>\n<p>\u8fd9\u91cc\u9075\u5faa\u7684\u610f\u601d\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u5339\u914d\uff0c\u5728\u4e00\u4e2a\u5b57\u6bcd\u7684\u6a21\u5f0f\u548c\u4e00\u4e2a\u975e\u7a7a\u7684\u5355\u8bcd str \u4e4b\u95f4\u6709\u4e00\u4e2a\u53cc\u5411\u8fde\u63a5\u7684\u6a21\u5f0f\u5bf9\u5e94\u3002(\u5982\u679c a \u5bf9\u5e94 s\uff0c\u90a3\u4e48 b \u4e0d\u5bf9\u5e94 s \u3002\u4f8b\u5982\uff0c\u7ed9\u5b9a\u7684\u6a21\u5f0f= &#8220;ab&#8221;\uff0cstr = &#8220;ss&#8221;\uff0c\u8fd4\u56de false \uff09\u3002<\/p>\n<h2>\u6837\u4f8b 1<\/h2>\n<pre><code>\u8f93\u5165: pattern = \"abab\" str = \"redblueredblue\" \u8f93\u51fa: true \u8bf4\u660e: \"a\"-&gt;\"red\",\"b\"-&gt;\"blue\" <\/code><\/pre>\n<h2>\u6837\u4f8b 2<\/h2>\n<pre><code>\u8f93\u5165: pattern = \"aaaa\" str = \"asdasdasdasd\" \u8f93\u51fa: true \u8bf4\u660e: \"a\"-&gt;\"asd\" <\/code><\/pre>\n<h2>\u6837\u4f8b 3<\/h2>\n<pre><code>\u8f93\u5165: pattern = \"aabb\" str = \"xyzabcxzyabc\" \u8f93\u51fa: false <\/code><\/pre>\n<h2>\u9898\u89e3\uff1a<\/h2>\n<p>\u7528\u6df1\u5ea6\u4f18\u5148\u641c\u7d22\u7b97\u6cd5\u3002 \u8fd9\u4e2a\u9898\u4e0d\u80fd\u4f7f\u7528\u52a8\u6001\u89c4\u5212\u6216\u8005\u8bb0\u5fc6\u5316\u641c\u7d22\uff0c\u56e0\u4e3a\u53c2\u6570\u5217\u8868\u4e2d mapping \u548c used \u65e0\u6cd5\u8bb0\u5f55\u5230\u8bb0\u5fc6\u5316\u7684\u54c8\u5e0c\u8868\u4e2d\u3002<\/p>\n<pre><code>class Solution:     \"\"\"     @param pattern: a string,denote pattern string     @param str: a string, denote matching string     @return: a boolean     \"\"\"     def wordPatternMatch(self, pattern, string):         return self.is_match(pattern, string, {}, set())      def is_match(self, pattern, string, mapping, used):         if not pattern:             return not string                      char = pattern[0]         if char in mapping:             word = mapping[char]             if not string.startswith(word):                 return False             return self.is_match(pattern[1:], string[len(word):], mapping, used)                      for i in range(len(string)):             word = string[:i + 1]             if word in used:                 continue                          used.add(word)             mapping[char] = word                          if self.is_match(pattern[1:], string[i + 1:], mapping, used):                 return True                          del mapping[char]             used.remove(word)                      return False <\/code><\/pre>\n<p>\u4e0a\u9762\u662f\u4e00\u9053\u539f\u9898\uff0c\u518d\u5206\u4eab\u4e00\u9053\u6ca1\u89c1\u8fc7\u7684\uff0c\u611f\u5174\u8da3\u7684\u53ef\u4ee5\u81ea\u5df1\u89e3\u4e00\u4e0b(\u53ea\u6709\u5927\u6982\u5370\u8c61\u4e86\uff0c\u4e0d\u77e5\u9053\u9898\u76ee\u63cf\u8ff0\u662f\u5426\u6709\u8bef\uff09<\/p>\n<p>\u7ed9\u4e00\u4e2a contact matrix, contact[j] == 1 \u8bf4\u660e i j \u662f connected, contact[j] == 0 \u8bf4\u660e i j \u4e0d\u662f connected; initial \u662f\u6700\u5f00\u59cb\u7684\u611f\u67d3\u7684\u4eba, \u8fd4\u56de\u6700\u540e\u6240\u6709\u611f\u67d3\u7684\u4eba<\/p>\n<h2>example:<\/h2>\n<pre><code>contact = [[1,1,1], [1,1,1], [1,1,1]] initial = [0] \u8fd4\u56de [0, 1, 2] \u89e3\u91ca: 0 1 2 \u4e92\u76f8 connected, 0 \u611f\u67d3, \u6240\u4ee5 0 \u8ba4\u8bc6\u7684\u6240\u6709\u4eba\u611f\u67d3, \u8fd4\u56de [0, 1, 2] <\/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>\u9ed1\u8f66\u9762\u7ecf\uff1a\u5b57\u6a21\u5f0f II \u8cc7\u6df1\u5927\u4f6c &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\/187568"}],"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=187568"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187568\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187568"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}