{"id":2357,"date":"2022-01-24T17:16:34","date_gmt":"2022-01-24T09:16:34","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2357"},"modified":"2022-01-24T17:16:35","modified_gmt":"2022-01-24T09:16:35","slug":"leetcodeday30","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday30\/","title":{"rendered":"leetcodeday30 &#8211;\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b57\u4e32"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;<code>s<\/code><strong>&nbsp;<\/strong>\u548c\u4e00\u4e9b&nbsp;<strong>\u957f\u5ea6\u76f8\u540c<\/strong>&nbsp;\u7684\u5355\u8bcd&nbsp;<code>words<\/code><strong>&nbsp;\u3002<\/strong>\u627e\u51fa&nbsp;<code>s<\/code><strong>&nbsp;<\/strong>\u4e2d\u6070\u597d\u53ef\u4ee5\u7531&nbsp;<code>words<\/code><strong>&nbsp;<\/strong>\u4e2d\u6240\u6709\u5355\u8bcd\u4e32\u8054\u5f62\u6210\u7684\u5b50\u4e32\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\u5b50\u4e32\u8981\u4e0e&nbsp;<code>words<\/code><strong>&nbsp;<\/strong>\u4e2d\u7684\u5355\u8bcd\u5b8c\u5168\u5339\u914d\uff0c<strong>\u4e2d\u95f4\u4e0d\u80fd\u6709\u5176\u4ed6\u5b57\u7b26&nbsp;<\/strong>\uff0c\u4f46\u4e0d\u9700\u8981\u8003\u8651&nbsp;<code>words<\/code><strong>&nbsp;<\/strong>\u4e2d\u5355\u8bcd\u4e32\u8054\u7684\u987a\u5e8f\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]\n<strong>\u8f93\u51fa\uff1a<\/strong><code>[0,9]<\/code>\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4ece\u7d22\u5f15 0 \u548c 9 \u5f00\u59cb\u7684\u5b50\u4e32\u5206\u522b\u662f \"barfoo\" \u548c \"foobar\" \u3002\n\u8f93\u51fa\u7684\u987a\u5e8f\u4e0d\u91cd\u8981, [9,0] \u4e5f\u662f\u6709\u6548\u7b54\u6848\u3002\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]\n<code><strong>\u8f93\u51fa\uff1a<\/strong>[]<\/code>\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>s = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\"]\n<strong>\u8f93\u51fa\uff1a<\/strong>[6,9,12]\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul><li><code>1 &lt;= s.length &lt;= 10<sup>4<\/sup><\/code><\/li><li><code>s<\/code>&nbsp;\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210<\/li><li><code>1 &lt;= words.length &lt;= 5000<\/code><\/li><li><code>1 &lt;= words[i].length &lt;= 30<\/code><\/li><li><code>words[i]<\/code>&nbsp;\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210<\/li><\/ul>\n\n\n\n<p>\u6328\u4e2a\u5339\u914d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=30 lang=python3\r\n#\r\n# &#91;30] \u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b50\u4e32\r\n#\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def findSubstring(self, s: str, words: List&#91;str]) -> List&#91;int]:\r\n        import copy\r\n        ls=len(s)\r\n        lw=len(words)\r\n        wordlen=len(words&#91;0])\r\n        dicts=dict()\r\n        res=&#91;]\r\n        for i in range(lw):\r\n            if words&#91;i] in  dicts:\r\n                dicts&#91;words&#91;i]]=dicts&#91;words&#91;i]]+1\r\n            else:\r\n                dicts&#91;words&#91;i]]=1\r\n        for i in range(ls-wordlen*lw+1):\r\n            new=copy.copy(dicts)\r\n            rev=1\r\n            for j in range(i,i+wordlen*lw,wordlen):\r\n                if s&#91;j:j+wordlen] in new and new&#91;s&#91;j:j+wordlen]]!=0:\r\n                    new&#91;s&#91;j:j+wordlen]]-=1\r\n                else:\r\n                    rev=0\r\n                    break\r\n            if rev==1:\r\n                res.append(i)\r\n        return res\r\n\r\n\r\n\r\n\r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"795\" height=\"254\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-285.png\" alt=\"\" class=\"wp-image-2358\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-285.png 795w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-285-300x96.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-285-768x245.png 768w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u5b57\u7b26\u4e32&nbsp;s&nbsp;\u548c\u4e00\u4e9b&nbsp;\u957f\u5ea6\u76f8\u540c&nbsp;\u7684\u5355\u8bcd&nbsp;words&#038;n &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/24\/leetcodeday30\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday30 &#8211;\u4e32\u8054\u6240\u6709\u5355\u8bcd\u7684\u5b57\u4e32<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2357"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2357"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2357\/revisions"}],"predecessor-version":[{"id":2359,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2357\/revisions\/2359"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2357"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}