{"id":681,"date":"2020-09-26T11:10:21","date_gmt":"2020-09-26T03:10:21","guid":{"rendered":"http:\/\/39.96.58.60\/?p=681"},"modified":"2022-10-18T16:38:23","modified_gmt":"2022-10-18T08:38:23","slug":"leetcode-842-%e5%b0%86%e6%95%b0%e7%bb%84%e6%8b%86%e5%88%86%e6%88%90%e6%96%90%e6%b3%a2%e9%82%a3%e5%a5%91%e5%ba%8f%e5%88%97","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=681","title":{"rendered":"Leetcode 842. \u5c06\u6570\u7ec4\u62c6\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5e8f\u5217"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32 <code>S<\/code>\uff0c\u6bd4\u5982 <code>S = \"123456579\"<\/code>\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217 <code>[123, 456, 579]<\/code>\u3002<\/p>\n<p>\u5f62\u5f0f\u4e0a\uff0c\u6590\u6ce2\u90a3\u5951\u5f0f\u5e8f\u5217\u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u5217\u8868 <code>F<\/code>\uff0c\u4e14\u6ee1\u8db3\uff1a<\/p>\n<ul>\n<li><code>0 &lt;= F[i] &lt;= 2^31 - 1<\/code>\uff0c\uff08\u4e5f\u5c31\u662f\u8bf4\uff0c\u6bcf\u4e2a\u6574\u6570\u90fd\u7b26\u5408 32 \u4f4d\u6709\u7b26\u53f7\u6574\u6570\u7c7b\u578b\uff09\uff1b<\/li>\n<li><code>F.length &gt;= 3<\/code>\uff1b<\/li>\n<li>\u5bf9\u4e8e\u6240\u6709\u7684<code>0 &lt;= i &lt; F.length - 2<\/code>\uff0c\u90fd\u6709 <code>F[i] + F[i+1] = F[i+2]<\/code> \u6210\u7acb\u3002<\/li>\n<\/ul>\n<p>\u53e6\u5916\uff0c\u8bf7\u6ce8\u610f\uff0c\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u6210\u5c0f\u5757\u65f6\uff0c\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e00\u5b9a\u4e0d\u8981\u4ee5\u96f6\u5f00\u5934\uff0c\u9664\u975e\u8fd9\u4e2a\u5757\u662f\u6570\u5b57 0 \u672c\u8eab\u3002<\/p>\n<p>\u8fd4\u56de\u4ece <code>S<\/code> \u62c6\u5206\u51fa\u6765\u7684\u4efb\u610f\u4e00\u7ec4\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217\u5757\uff0c\u5982\u679c\u4e0d\u80fd\u62c6\u5206\u5219\u8fd4\u56de <code>[]<\/code>\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>\"123456579\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[123,456,579]\n\n<\/pre>\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165: <\/strong>\"11235813\"\n\n<strong>\u8f93\u51fa: <\/strong>[1,1,2,3,5,8,13]\n\n<\/pre>\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165: <\/strong>\"112358130\"\n\n<strong>\u8f93\u51fa: <\/strong>[]\n\n<strong>\u89e3\u91ca: <\/strong>\u8fd9\u9879\u4efb\u52a1\u65e0\u6cd5\u5b8c\u6210\u3002\n\n<\/pre>\n<p><strong>\u793a\u4f8b 4\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>\"0123\"\n\n<strong>\u8f93\u51fa\uff1a<\/strong>[]\n\n<strong>\u89e3\u91ca\uff1a<\/strong>\u6bcf\u4e2a\u5757\u7684\u6570\u5b57\u4e0d\u80fd\u4ee5\u96f6\u5f00\u5934\uff0c\u56e0\u6b64 \"01\"\uff0c\"2\"\uff0c\"3\" \u4e0d\u662f\u6709\u6548\u7b54\u6848\u3002\n\n<\/pre>\n<p><strong>\u793a\u4f8b 5\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165: <\/strong>\"1101111\"\n\n<strong>\u8f93\u51fa: <\/strong>[110, 1, 111]\n\n<strong>\u89e3\u91ca: <\/strong>\u8f93\u51fa [11,0,11,11] \u4e5f\u540c\u6837\u88ab\u63a5\u53d7\u3002\n\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ol>\n<li><code>1 &lt;= S.length&nbsp;&lt;= 200<\/code><\/li>\n<li>\u5b57\u7b26\u4e32 <code>S<\/code> \u4e2d\u53ea\u542b\u6709\u6570\u5b57\u3002<\/li>\n<\/ol>\n<p>**\u96be\u5ea6**: Medium<\/p>\n<p>**\u6807\u7b7e**: \u8d2a\u5fc3\u7b97\u6cd5\u3001 \u5b57\u7b26\u4e32\u3001 \u56de\u6eaf\u7b97\u6cd5\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\uff1a148 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8635.57% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.7 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8636.81% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u56de\u6eaf\n    \u5177\u4f53\u5b9e\u73b0\u89c1\u4ee3\u7801\u6ce8\u91ca\n\"\"\"\nclass Solution:\n    def splitIntoFibonacci(self, S: str) -&gt; List[int]:\n\n        def backtrack(S, current):\n            if S == '' and len(current) &gt; 2:    # \u5b57\u7b26\u4e32\u5747\u5904\u7406\u5b8c\uff0c\u4e14\u5f53\u524d\u5e8f\u5217\u957f\u5ea6\u5927\u4e8e2\uff0c \u8fd4\u56de\u6700\u7ec8\u7ed3\u679c\n                return True\n\n            if S == '': # \u5f53\u5b57\u7b26\u4e32\u5904\u7406\u5b8c\u65f6\uff0c\u8df3\u51fa\n                return\n\n            for i in range(1, len(S)+1): # \u904d\u5386\u5f53\u524d\u5b57\u7b26\u4e32\n                if (S[0] == '0' and i == 1) or (S[0] != '0'):   # \u6392\u9664\u4ee50 \u5f00\u5934\u7684\u975e0\u6570\uff0c \u5982 01 02 \u7b49\n                    if int(S[:i]) &lt; (2**31-1) and (len(current) &lt; 2 or int(S[:i]) == int(current[-1]) + int(current[-2])):  # \u6570\u5b57\u9650\u5236\uff1b\u957f\u5ea6\u5224\u65ad\uff0c\u5982\u957f\u5ea6\u5c0f\u4e8e2\uff0c\u76f4\u63a5\u6dfb\u52a0\uff0c\u5982\u957f\u5ea6\u5927\u4e8e2\uff0c\u9700\u5224\u65ad\u548c\n                        current.append(S[:i])\n                        if backtrack(S[i:], current):\n                            return current\n                        current.pop()\n\n        result = backtrack(S, [])\n        if result:\n            return result\n        else:\n            return []<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26\u4e32 S\uff0c\u6bd4\u5982 S = &#8220;123456579&#8221;\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u5206\u6210\u6590\u6ce2\u90a3\u5951\u5f0f\u7684\u5e8f\u5217 [123, 4&#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\/681"}],"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=681"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":682,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions\/682"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}