{"id":2437,"date":"2022-01-27T11:05:31","date_gmt":"2022-01-27T03:05:31","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2437"},"modified":"2022-01-27T11:05:32","modified_gmt":"2022-01-27T03:05:32","slug":"leetcodeday93","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/27\/leetcodeday93\/","title":{"rendered":"leetcodeday93 &#8211;\u590d\u539f IP \u5730\u5740"},"content":{"rendered":"\n<p><strong>\u6709\u6548 IP \u5730\u5740<\/strong>&nbsp;\u6b63\u597d\u7531\u56db\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6574\u6570\u4f4d\u4e8e&nbsp;<code>0<\/code>&nbsp;\u5230&nbsp;<code>255<\/code>&nbsp;\u4e4b\u95f4\u7ec4\u6210\uff0c\u4e14\u4e0d\u80fd\u542b\u6709\u524d\u5bfc&nbsp;<code>0<\/code>\uff09\uff0c\u6574\u6570\u4e4b\u95f4\u7528&nbsp;<code>'.'<\/code>&nbsp;\u5206\u9694\u3002<\/p>\n\n\n\n<ul><li>\u4f8b\u5982\uff1a&#8221;0.1.2.201&#8243; \u548c &#8220;192.168.1.1&#8221; \u662f&nbsp;<strong>\u6709\u6548<\/strong>&nbsp;IP \u5730\u5740\uff0c\u4f46\u662f &#8220;0.011.255.245&#8221;\u3001&#8221;192.168.1.312&#8243; \u548c &#8220;192.168@1.1&#8221; \u662f&nbsp;<strong>\u65e0\u6548<\/strong>&nbsp;IP \u5730\u5740\u3002<\/li><\/ul>\n\n\n\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32&nbsp;<code>s<\/code>&nbsp;\uff0c\u7528\u4ee5\u8868\u793a\u4e00\u4e2a IP \u5730\u5740\uff0c\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684<strong>\u6709\u6548 IP \u5730\u5740<\/strong>\uff0c\u8fd9\u4e9b\u5730\u5740\u53ef\u4ee5\u901a\u8fc7\u5728&nbsp;<code>s<\/code>&nbsp;\u4e2d\u63d2\u5165&nbsp;<code>'.'<\/code>&nbsp;\u6765\u5f62\u6210\u3002\u4f60\u4e0d\u80fd\u91cd\u65b0\u6392\u5e8f\u6216\u5220\u9664&nbsp;<code>s<\/code>&nbsp;\u4e2d\u7684\u4efb\u4f55\u6570\u5b57\u3002\u4f60\u53ef\u4ee5\u6309&nbsp;<strong>\u4efb\u4f55<\/strong>&nbsp;\u987a\u5e8f\u8fd4\u56de\u7b54\u6848\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>s = \"25525511135\"\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;\"255.255.11.135\",\"255.255.111.35\"]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>s = \"0000\"\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;\"0.0.0.0\"]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>s = \"1111\"\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;\"1.1.1.1\"]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 4\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>s = \"010010\"\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;\"0.10.0.10\",\"0.100.1.0\"]<\/code><\/pre>\n\n\n\n<p class=\"has-light-pink-background-color has-background\">\u601d\u8def\u56de\u6eaf\u7b97\u6cd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># @lc app=leetcode.cn id=93 lang=python3\r\n#\r\n# &#91;93] \u590d\u539f IP \u5730\u5740\r\n#\r\n#\u56de\u6eaf\u7b97\u6cd5\uff1a\r\n# void backtracking(\u53c2\u6570) {\r\n#     if (\u7ec8\u6b62\u6761\u4ef6) {\r\n#         \u5b58\u653e\u7ed3\u679c;\r\n#         return;\r\n#     }\r\n\r\n#     for (\u9009\u62e9\uff1a\u672c\u5c42\u96c6\u5408\u4e2d\u5143\u7d20\uff08\u6811\u4e2d\u8282\u70b9\u5b69\u5b50\u7684\u6570\u91cf\u5c31\u662f\u96c6\u5408\u7684\u5927\u5c0f\uff09) {\r\n#         \u5904\u7406\u8282\u70b9;\r\n#         backtracking(\u8def\u5f84\uff0c\u9009\u62e9\u5217\u8868); \/\/ \u9012\u5f52\r\n#         \u56de\u6eaf\uff0c\u64a4\u9500\u5904\u7406\u7ed3\u679c\r\n#     }\r\n# }\r\n\r\n# @lc code=start\r\nclass Solution:\r\n    def restoreIpAddresses(self, s: str) -> List&#91;str]:\r\n        def backtracking(n,now,k,rev):\r\n            if  k==1:\r\n                if n-now in range(1,4) and str(int(s&#91;now:n]))==s&#91;now:n] and int(s&#91;now:n]) in range(0,256):\r\n                    res.append(rev+s&#91;now:n]) \r\n                return\r\n            for i in range(1,4):\r\n                if now+i&lt;n and str(int(s&#91;now:now+i]))==s&#91;now:now+i] and int(s&#91;now:now+i]) in range(0,256):\r\n                    now=now+i\r\n                    backtracking(n,now,k-1,rev+s&#91;now-i:now]+\".\")\r\n                    now=now-i\r\n        # s = \"25525511125\"\r\n        rev=str()\r\n        res=list()\r\n        backtracking(len(s),0,4,rev)\r\n        return res\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=\"674\" height=\"257\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-301.png\" alt=\"\" class=\"wp-image-2438\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-301.png 674w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-301-300x114.png 300w\" sizes=\"(max-width: 674px) 100vw, 674px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u6548 IP \u5730\u5740&nbsp;\u6b63\u597d\u7531\u56db\u4e2a\u6574\u6570\uff08\u6bcf\u4e2a\u6574\u6570\u4f4d\u4e8e&nbsp;0&nbsp;\u5230&nbsp;255&#038;nbs &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/27\/leetcodeday93\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday93 &#8211;\u590d\u539f IP \u5730\u5740<\/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\/2437"}],"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=2437"}],"version-history":[{"count":2,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2437\/revisions"}],"predecessor-version":[{"id":2440,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2437\/revisions\/2440"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2437"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}