{"id":179,"date":"2022-01-06T05:43:19","date_gmt":"2022-01-05T21:43:19","guid":{"rendered":"https:\/\/www.wennroy.com\/?p=179"},"modified":"2022-01-06T06:55:54","modified_gmt":"2022-01-05T22:55:54","slug":"1576-replace-all-s-to-avoid-consecutive-repeating-characters","status":"publish","type":"post","link":"https:\/\/wennroy.com\/index.php\/2022\/01\/06\/1576-replace-all-s-to-avoid-consecutive-repeating-characters\/","title":{"rendered":"1576. \u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7"},"content":{"rendered":"<h1>1576. \u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7<\/h1>\n<p>\u7ed9\u4f60\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u548c &#8216;?&#8217; \u5b57\u7b26\u7684\u5b57\u7b26\u4e32 s\uff0c\u8bf7\u4f60\u5c06\u6240\u6709\u7684 &#8216;?&#8217; \u8f6c\u6362\u4e3a\u82e5\u5e72\u5c0f\u5199\u5b57\u6bcd\uff0c\u4f7f\u6700\u7ec8\u7684\u5b57\u7b26\u4e32\u4e0d\u5305\u542b\u4efb\u4f55 \u8fde\u7eed\u91cd\u590d \u7684\u5b57\u7b26\u3002<\/p>\n<p>\u663e\u7136\u4e09\u4e2a\u5b57\u7b26\u4e32\u5df2\u7ecf\u8db3\u591f\u3002\u5224\u65ad\u7531\u4e8e\u987a\u5e8f\u662f\u5148\u5224\u65ad\u5de6\u540e\u5224\u65ad\u53f3\uff0c\u90a3\u4e48\u53f3\u8fb9\u82e5\u505a\u4e86\u4fee\u6539\uff0c\u5373\u4e0d\u80fd\u4fdd\u8bc1\u5de6\u8fb9\u4e0d\u4e00\u6837\u3002\u56e0\u6b64\u7ee7\u7eed\u5faa\u73af\u5224\u65ad\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def modifyString(self, s: str) -&gt; str:\n        n = len(s)\n        for index, a in enumerate(s):\n            if a == &#039;?&#039;:\n                a = &#039;a&#039;\n                while True:\n                    left = False\n                    right = False\n                    if index &gt; 0 and s[index - 1] == a:\n                            a = chr(ord(s[index - 1]) + 1)\n                            left = True\n                    if index &lt; n-1 and s[index + 1] == a:\n                            a = chr(ord(s[index + 1]) + 1)\n                            left = False\n                            right = True\n                    if not left and not right:\n                        # print(a)\n                        break\n                    if left:\n                        break\n                s = s.replace(&quot;?&quot;,a,1)\n                # print(s)\n        return s<\/code><\/pre>\n<p><strong>\u5b98\u65b9\u6807\u7b54\uff1a<\/strong><br \/>\n\u5b98\u65b9\u4ec5\u5728\u4e09\u4e2a\u5b57\u7b26\u4e2d\u9009\u53d6\u3002<\/p>\n<pre><code class=\"language-python\">class Solution:\n    def modifyString(self, s: str) -&gt; str:\n        res = list(s)\n        n = len(res)\n        for i in range(n):\n            if res[i] == &#039;?&#039;:\n                for b in &quot;abc&quot;:\n                    if not (i &gt; 0 and res[i - 1] == b or i &lt; n - 1 and res[i + 1] == b):\n                        res[i] = b\n                        break\n        return &#039;&#039;.join(res)<\/code><\/pre>\n<p>\u6765\u6e90\uff1a\u529b\u6263\uff08LeetCode\uff09<br \/>\n\u94fe\u63a5\uff1a<a href=\"https:\/\/leetcode-cn.com\/problems\/replace-all-s-to-avoid-consecutive-repeating-characters\">https:\/\/leetcode-cn.com\/problems\/replace-all-s-to-avoid-consecutive-repeating-characters<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1576. \u66ff\u6362\u6240\u6709\u7684\u95ee\u53f7 \u7ed9\u4f60\u4e00\u4e2a\u4ec5\u5305\u542b\u5c0f\u5199\u82f1\u6587 &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[6,11],"tags":[13,15],"class_list":["post-179","post","type-post","status-publish","format-standard","hentry","category-leetcode","category-strings","tag-13","tag-15"],"_links":{"self":[{"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/posts\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":2,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":181,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/posts\/179\/revisions\/181"}],"wp:attachment":[{"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wennroy.com\/index.php\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}