{"id":311,"date":"2020-09-26T10:23:42","date_gmt":"2020-09-26T02:23:42","guid":{"rendered":"http:\/\/39.96.58.60\/?p=311"},"modified":"2022-10-18T16:43:25","modified_gmt":"2022-10-18T08:43:25","slug":"leetcode-844-%e6%af%94%e8%be%83%e5%90%ab%e9%80%80%e6%a0%bc%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=311","title":{"rendered":"Leetcode 844. \u6bd4\u8f83\u542b\u9000\u683c\u7684\u5b57\u7b26\u4e32"},"content":{"rendered":"<p>\u7ed9\u5b9a <code>S<\/code> \u548c <code>T<\/code> \u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5f53\u5b83\u4eec\u5206\u522b\u88ab\u8f93\u5165\u5230\u7a7a\u767d\u7684\u6587\u672c\u7f16\u8f91\u5668\u540e\uff0c\u5224\u65ad\u4e8c\u8005\u662f\u5426\u76f8\u7b49\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002 <code>#<\/code> \u4ee3\u8868\u9000\u683c\u5b57\u7b26\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u5982\u679c\u5bf9\u7a7a\u6587\u672c\u8f93\u5165\u9000\u683c\u5b57\u7b26\uff0c\u6587\u672c\u7ee7\u7eed\u4e3a\u7a7a\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>S = \"ab#c\", T = \"ad#c\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n\n<strong>\u89e3\u91ca\uff1a<\/strong>S \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cac\u201d\u3002\n\n<\/pre>\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>S = \"ab##\", T = \"c#d#\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n\n<strong>\u89e3\u91ca\uff1a<\/strong>S \u548c T \u90fd\u4f1a\u53d8\u6210 \u201c\u201d\u3002\n\n<\/pre>\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>S = \"a##c\", T = \"#a#c\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>true\n\n<strong>\u89e3\u91ca\uff1a<\/strong>S \u548c T \u90fd\u4f1a\u53d8\u6210 \u201cc\u201d\u3002\n\n<\/pre>\n<p><strong>\u793a\u4f8b 4\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>S = \"a#c\", T = \"b\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>false\n\n<strong>\u89e3\u91ca\uff1a<\/strong>S \u4f1a\u53d8\u6210 \u201cc\u201d\uff0c\u4f46 T \u4ecd\u7136\u662f \u201cb\u201d\u3002<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ol>\n<li><code>1 &lt;= S.length &lt;= 200<\/code><\/li>\n<li><code>1 &lt;= T.length &lt;= 200<\/code><\/li>\n<li><code>S<\/code> \u548c <code>T<\/code> \u53ea\u542b\u6709\u5c0f\u5199\u5b57\u6bcd\u4ee5\u53ca\u5b57\u7b26 <code>'#'<\/code>\u3002<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><strong>\u8fdb\u9636\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f60\u53ef\u4ee5\u7528 <code>O(N)<\/code> \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u548c <code>O(1)<\/code> \u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u89e3\u51b3\u8be5\u95ee\u9898\u5417\uff1f<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>**\u96be\u5ea6**: Easy<\/p>\n<p>**\u6807\u7b7e**: \u6808\u3001 \u53cc\u6307\u9488\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\uff1a28 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8699.39% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.5 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e865.32% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u6808\n\"\"\"\n\nclass Solution:\n    def backspaceCompare(self, S: str, T: str) -&gt; bool:\n        s, t = [], []\n        for i in S:\n            if i == '#':    # \u5982\u679c\u662f# \uff0c\u51fa\u6808\u9000\u683c\n                if s:\n                    s.pop()\n            else:           # \u5b57\u6bcd\uff0c\u8fdb\u6808\n                s.append(i)\n\n        for i in T:\n            if i == '#':\n                if t:\n                    t.pop()\n            else:\n                t.append(i)\n        return s == t<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a S \u548c T \u4e24\u4e2a\u5b57\u7b26\u4e32\uff0c\u5f53\u5b83\u4eec\u5206\u522b\u88ab\u8f93\u5165\u5230\u7a7a\u767d\u7684\u6587\u672c\u7f16\u8f91\u5668\u540e\uff0c\u5224\u65ad\u4e8c\u8005\u662f\u5426\u76f8\u7b49\uff0c\u5e76\u8fd4\u56de\u7ed3\u679c\u3002 # \u4ee3\u8868\u9000&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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\/311"}],"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=311"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/311\/revisions"}],"predecessor-version":[{"id":312,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/311\/revisions\/312"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=311"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}