{"id":465,"date":"2020-09-26T10:44:54","date_gmt":"2020-09-26T02:44:54","guid":{"rendered":"http:\/\/39.96.58.60\/?p=465"},"modified":"2022-10-18T16:39:14","modified_gmt":"2022-10-18T08:39:14","slug":"leetcode-392-%e5%88%a4%e6%96%ad%e5%ad%90%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=465","title":{"rendered":"Leetcode 392. \u5224\u65ad\u5b50\u5e8f\u5217"},"content":{"rendered":"<p>\u7ed9\u5b9a\u5b57\u7b26\u4e32 <strong>s<\/strong> \u548c <strong>t<\/strong> \uff0c\u5224\u65ad <strong>s<\/strong> \u662f\u5426\u4e3a <strong>t<\/strong> \u7684\u5b50\u5e8f\u5217\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u8ba4\u4e3a <strong>s<\/strong> \u548c <strong>t<\/strong> \u4e2d\u4ec5\u5305\u542b\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002\u5b57\u7b26\u4e32 <strong>t<\/strong> \u53ef\u80fd\u4f1a\u5f88\u957f\uff08\u957f\u5ea6 ~= 500,000\uff09\uff0c\u800c <strong>s<\/strong> \u662f\u4e2a\u77ed\u5b57\u7b26\u4e32\uff08\u957f\u5ea6 &lt;=100\uff09\u3002<\/p>\n<p>\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\u662f\u539f\u59cb\u5b57\u7b26\u4e32\u5220\u9664\u4e00\u4e9b\uff08\u4e5f\u53ef\u4ee5\u4e0d\u5220\u9664\uff09\u5b57\u7b26\u800c\u4e0d\u6539\u53d8\u5269\u4f59\u5b57\u7b26\u76f8\u5bf9\u4f4d\u7f6e\u5f62\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\uff08\u4f8b\u5982\uff0c<code>\"ace\"<\/code>\u662f<code>\"abcde\"<\/code>\u7684\u4e00\u4e2a\u5b50\u5e8f\u5217\uff0c\u800c<code>\"aec\"<\/code>\u4e0d\u662f\uff09\u3002<\/p>\n<p><strong>\u793a\u4f8b&nbsp;1:<\/strong><\/p>\n<p><strong>s<\/strong> = <code>\"abc\"<\/code>, <strong>t<\/strong> = <code>\"ahbgdc\"<\/code><\/p>\n<p>\u8fd4\u56de&nbsp;<code>true<\/code>.<\/p>\n<p><strong>\u793a\u4f8b&nbsp;2:<\/strong><\/p>\n<p><strong>s<\/strong> = <code>\"axc\"<\/code>, <strong>t<\/strong> = <code>\"ahbgdc\"<\/code><\/p>\n<p>\u8fd4\u56de&nbsp;<code>false<\/code>.<\/p>\n<p><strong>\u540e\u7eed\u6311\u6218<\/strong> <strong>:<\/strong><\/p>\n<p>\u5982\u679c\u6709\u5927\u91cf\u8f93\u5165\u7684 S\uff0c\u79f0\u4f5cS1, S2, &#8230; , Sk \u5176\u4e2d k &gt;= 10\u4ebf\uff0c\u4f60\u9700\u8981\u4f9d\u6b21\u68c0\u67e5\u5b83\u4eec\u662f\u5426\u4e3a T \u7684\u5b50\u5e8f\u5217\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f1a\u600e\u6837\u6539\u53d8\u4ee3\u7801\uff1f<\/p>\n<p><strong>\u81f4\u8c22:<\/strong><\/p>\n<p>\u7279\u522b\u611f\u8c22<strong> <\/strong><a href=\"https:\/\/leetcode.com\/pbrother\/\">@pbrother&nbsp;<\/a>\u6dfb\u52a0\u6b64\u95ee\u9898\u5e76\u4e14\u521b\u5efa\u6240\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u8d2a\u5fc3\u7b97\u6cd5\u3001 \u4e8c\u5206\u67e5\u627e\u3001 \u52a8\u6001\u89c4\u5212\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a36 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8639.48% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.6 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8688.49% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u53cc\u6307\u9488\u6cd5\n\"\"\"\nclass Solution:\n    def isSubsequence(self, s: str, t: str) -&gt; bool:\n        i, j = 0, 0\n        while i &lt; len(s) and j &lt; len(t) :\n            if s[i] == t[j]:\n                i += 1\n                j += 1\n            else:\n                j += 1\n        if i == len(s):\n            return True\n        else:\n            return False\n\n\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u5b57\u7b26\u4e32 s \u548c t \uff0c\u5224\u65ad s \u662f\u5426\u4e3a t \u7684\u5b50\u5e8f\u5217\u3002 \u4f60\u53ef\u4ee5\u8ba4\u4e3a s \u548c t \u4e2d\u4ec5\u5305\u542b\u82f1\u6587\u5c0f\u5199\u5b57\u6bcd\u3002\u5b57\u7b26&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/465"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=465"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":466,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/465\/revisions\/466"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}