{"id":74396,"date":"2026-02-09T18:49:32","date_gmt":"2026-02-09T10:49:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/74396.html"},"modified":"2026-02-09T18:49:32","modified_gmt":"2026-02-09T10:49:32","slug":"leetcode%e5%9b%9e%e6%ba%af%e7%ae%97%e6%b3%95part2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/74396.html","title":{"rendered":"Leetcode\u56de\u6eaf\u7b97\u6cd5part2"},"content":{"rendered":"<h2>93. \u590d\u539f IP \u5730\u5740<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32 s&#xff0c;\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u5408\u6cd5 IP \u5730\u5740\u3002<\/p>\n<h4>\u4ec0\u4e48\u662f\u201c\u5408\u6cd5 IP\u201d&#xff1f;<\/h4>\n<p>\u4e00\u4e2a IP \u5730\u5740\u5fc5\u987b\u6ee1\u8db3&#xff1a;<\/p>\n<li>\n<p>\u7531 4 \u6bb5\u7ec4\u6210&#xff0c;\u7528 . \u5206\u9694<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u6bb5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u503c\u5728 0 ~ 255<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u6709\u524d\u5bfc 0&#xff08;\u9664\u975e\u5c31\u662f &#034;0&#034;&#xff09;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\n<p>&#034;25525511135&#034; \u2192 &#034;255.255.11.135&#034;\u3001&#034;255.255.111.35&#034;<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e3a\u4ec0\u4e48\u8fd9\u662f\u56de\u6eaf\u95ee\u9898&#xff1f;<\/h3>\n<p>\u56e0\u4e3a\u9898\u76ee\u8981\u6c42\u7684\u662f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u679a\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u5207\u5272\u65b9\u5f0f<\/p>\n<\/li>\n<li>\n<p>\u5e76\u4e14\u6bcf\u4e00\u79cd\u5207\u5272\u65b9\u5f0f\u90fd\u8981\u5224\u65ad\u662f\u5426\u5408\u6cd5<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u4e00\u770b\u5230&#xff1a;<\/p>\n<p>\u201c\u5207\u5272\u5b57\u7b26\u4e32 &#043; \u6240\u6709\u53ef\u80fd\u65b9\u6848\u201d<\/p>\n<p>\u5c31\u8981\u7acb\u523b\u60f3\u5230&#xff1a;<\/p>\n<p>\u56de\u6eaf&#xff08;\u5207\u5272\u95ee\u9898&#xff09;<\/p>\n<hr \/>\n<h3>\u628a\u95ee\u9898\u62bd\u8c61\u6210\u4e00\u68f5\u6811&#xff08;\u6838\u5fc3\u7406\u89e3&#xff09;<\/h3>\n<p>\u53ef\u4ee5\u628a\u95ee\u9898\u7406\u89e3\u4e3a&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5728\u5b57\u7b26\u4e32\u4e2d \u653e 3 \u4e2a\u70b9<\/p>\n<\/li>\n<li>\n<p>\u628a\u5b57\u7b26\u4e32\u5207\u6210 4 \u6bb5<\/p>\n<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff1a;&#034;25525511135&#034;<\/p>\n<p>\u7b2c\u4e00\u5200     \u7b2c\u4e8c\u5200     \u7b2c\u4e09\u5200<br \/>\n\u2193           \u2193           \u2193<br \/>\n255 | 255 | 11 | 135<\/p>\n<p>\u6811\u7684\u542b\u4e49<\/p>\n<table>\n<tr>\u56de\u6eaf\u6982\u5ff5\u672c\u9898\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>\u6811\u7684\u6df1\u5ea6<\/td>\n<td>\u5df2\u7ecf\u653e\u4e86\u51e0\u4e2a\u70b9&#xff08;n&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6bcf\u4e00\u5c42<\/td>\n<td>\u51b3\u5b9a\u5f53\u524d\u8fd9\u4e00\u6bb5\u7684\u7ed3\u5c3e<\/td>\n<\/tr>\n<tr>\n<td>\u6bcf\u4e2a\u8282\u70b9<\/td>\n<td>\u4e00\u4e2a\u5408\u6cd5\u7684 IP \u6bb5<\/td>\n<\/tr>\n<tr>\n<td>\u4e00\u6761\u8def\u5f84<\/td>\n<td>\u4e00\u4e2a\u5b8c\u6574 IP \u5730\u5740<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f449; \u5f53 \u5df2\u7ecf\u653e\u4e86 3 \u4e2a\u70b9&#xff0c;\u5269\u4e0b\u7684\u90a3\u4e00\u6bb5\u5fc5\u987b\u4e00\u6b21\u6027\u5224\u65ad\u662f\u5426\u5408\u6cd5\u3002<\/p>\n<hr \/>\n<h3 style=\"background-color:transparent\">\u6574\u4f53\u89e3\u6cd5\u62c6\u89e3&#xff08;\u4e24\u90e8\u5206&#xff09;<\/h3>\n<h4>\u2705 \u7b2c\u4e00\u90e8\u5206&#xff1a;\u5408\u6cd5\u6027\u5224\u65ad&#xff08;isValid&#xff09;<\/h4>\n<p>\u8fd9\u662f\u672c\u9898\u7684**\u201c\u89c4\u5219\u5f15\u64ce\u201d**&#xff0c;\u8d1f\u8d23\u5224\u65ad&#xff1a;<\/p>\n<p>s[start..end] \u80fd\u4e0d\u80fd\u4f5c\u4e3a\u4e00\u4e2a IP \u6bb5<\/p>\n<hr \/>\n<h4>\u2705 \u7b2c\u4e8c\u90e8\u5206&#xff1a;\u56de\u6eaf\u5207\u5272\u5b57\u7b26\u4e32<\/h4>\n<ul>\n<li>\n<p>\u7528\u56de\u6eaf\u5c1d\u8bd5\u5728\u4e0d\u540c\u4f4d\u7f6e\u63d2\u5165 .<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u63d2\u5165\u4e00\u6b21&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u786e\u5b9a\u4e86\u4e00\u6bb5<\/p>\n<\/li>\n<li>\n<p>\u63d2\u5165 3 \u4e2a\u70b9\u540e&#xff0c;\u68c0\u67e5\u6700\u540e\u4e00\u6bb5<\/p>\n<\/li>\n<\/ul>\n<p>class Solution {<br \/>\npublic:<\/p>\n<p>    vector&lt;string&gt;result;<\/p>\n<p>    bool isValid(const string&amp;s,int start,int end){<br \/>\n        if(start&gt;end)return false;<br \/>\n        if(s[start]&#061;&#061;&#039;0&#039; &amp;&amp; start !&#061; end){<br \/>\n            return false;<br \/>\n        }<br \/>\n        int num &#061; 0;<br \/>\n        for(int i &#061; start;i&lt;&#061;end;i&#043;&#043;){<br \/>\n            if(s[i]&gt;&#039;9&#039;||s[i]&lt;&#039;0&#039;)return false;<br \/>\n            num &#061; num*10&#043;(s[i]-&#039;0&#039;);<br \/>\n            if(num&gt;255)return false;<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<\/p>\n<p>    void backtracking(string&amp; s ,int n ,int startIndex){<br \/>\n        if(n&#061;&#061;3){<br \/>\n            if(isValid(s,startIndex,s.size()-1)){<br \/>\n                 result.push_back(s);<br \/>\n            }<br \/>\n            return ;<br \/>\n        }<br \/>\n        for(int i &#061; startIndex;i&lt;s.size();i&#043;&#043;){<br \/>\n            if(isValid(s,startIndex,i)){<br \/>\n                s.insert(s.begin()&#043;i&#043;1,&#039;.&#039;);<br \/>\n                n&#043;&#043;;<br \/>\n                backtracking(s,n,i&#043;2);<br \/>\n                n&#8211;;<br \/>\n                s.erase(s.begin()&#043;i&#043;1);<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    vector&lt;string&gt; restoreIpAddresses(string s) {<br \/>\n        result.clear();<br \/>\n        if (s.size() &lt; 4 || s.size() &gt; 12) return result; \/\/ \u7b97\u662f\u526a\u679d\u4e86<br \/>\n        backtracking(s, 0, 0);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>78. \u5b50\u96c6<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42\u7684\u662f&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5b83\u7684\u6240\u6709\u5b50\u96c6&#xff08;\u5e42\u96c6&#xff09;\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;[1,2]<\/p>\n<p>[] [1] [2] [1,2] <\/p>\n<h4>\u5b50\u96c6\u95ee\u9898\u7684\u6700\u5927\u7279\u70b9<\/h4>\n<ul>\n<li>\n<p>\u4e0d\u8981\u6c42\u56fa\u5b9a\u957f\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e2a\u5143\u7d20&#xff1a;\u9009 or \u4e0d\u9009<\/p>\n<\/li>\n<li>\n<p>\u6240\u6709\u53ef\u80fd\u60c5\u51b5\u90fd\u8981<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u4e00\u53e5\u8bdd\u5224\u65ad&#xff1a;<\/p>\n<p>\u201c\u6bcf\u4e2a\u5143\u7d20\u90fd\u6709\u9009 \/ \u4e0d\u9009\u4e24\u79cd\u72b6\u6001\u201d \u2192 \u5b50\u96c6\u95ee\u9898 \u2192 \u56de\u6eaf<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u628a\u5b50\u96c6\u95ee\u9898\u62bd\u8c61\u6210\u4e00\u68f5\u6811&#xff08;\u975e\u5e38\u91cd\u8981&#xff09;<\/h3>\n<p>\u4ee5 nums &#061; [1,2,3] \u4e3a\u4f8b&#xff1a;<\/p>\n<p>[]<br \/>\n[1]<br \/>\n[2]<br \/>\n[1,2]<\/p>\n<p>\u4f46\u5728\u4ee3\u7801\u5b9e\u73b0\u4e2d&#xff0c;\u6211\u4eec\u901a\u5e38\u4e0d\u663e\u5f0f\u5199\u201c\u9009 \/ \u4e0d\u9009\u201d\u4e24\u6761\u5206\u652f&#xff0c;\u800c\u662f\u7528&#xff1a;<\/p>\n<p>for \u5faa\u73af &#043; startIndex&#xff0c;\u81ea\u7136\u679a\u4e3e\u201c\u9009\u54ea\u4e9b\u201d<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u5b50\u96c6 vs \u7ec4\u5408&#xff08;\u6838\u5fc3\u8ba4\u77e5&#xff09;<\/h3>\n<p>\u8fd9\u662f\u5f88\u591a\u4eba\u7b2c\u4e00\u6b21\u5b66\u5b50\u96c6\u65f6\u6700\u5bb9\u6613\u6df7\u7684\u70b9&#x1f447;<\/p>\n<h4>\u7ec4\u5408\u95ee\u9898&#xff08;\u5982 combine&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u53ea\u6709 path.size() &#061;&#061; k \u624d\u6536\u96c6\u7ed3\u679c<\/p>\n<\/li>\n<li>\n<p>\u6709\u660e\u786e\u201c\u7ec8\u6b62\u6761\u4ef6\u201d<\/p>\n<\/li>\n<\/ul>\n<h4>\u5b50\u96c6\u95ee\u9898&#xff08;\u672c\u9898&#xff09;<\/h4>\n<p>\u6bcf\u4e00\u4e2a\u8282\u70b9&#xff0c;\u90fd\u662f\u4e00\u4e2a\u5408\u6cd5\u5b50\u96c6<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7a7a\u96c6\u662f\u5b50\u96c6<\/p>\n<\/li>\n<li>\n<p>\u4efb\u4f55\u4e2d\u95f4\u72b6\u6001\u90fd\u662f\u5b50\u96c6<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u9700\u8981\u7b49\u5230\u201c\u53f6\u5b50\u8282\u70b9\u201d<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u8fd9\u5c31\u662f\u4f60\u4ee3\u7801\u91cc\u8fd9\u53e5\u7684\u771f\u6b63\u542b\u4e49&#xff1a;<\/p>\n<p>result.push_back(sub);<\/p>\n<hr \/>\n<h3>\u56db\u3001\u56de\u6eaf\u4e09\u90e8\u66f2&#xff08;\u5bf9\u5e94\u672c\u9898&#xff09;<\/h3>\n<h4>\u2705 \u2460 \u56de\u6eaf\u51fd\u6570\u53c2\u6570<\/h4>\n<p>void backtracking(vector&lt;int&gt;&amp; nums, int startIndex)<\/p>\n<ul>\n<li>\n<p>nums&#xff1a;\u539f\u6570\u7ec4<\/p>\n<\/li>\n<li>\n<p>startIndex&#xff1a;\u4e0b\u4e00\u6b21\u53ef\u9009\u62e9\u5143\u7d20\u7684\u8d77\u70b9<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; startIndex \u7684\u4f5c\u7528\u4f9d\u7136\u662f&#xff1a; \u9632\u6b62\u51fa\u73b0 [1,2] \u548c [2,1] \u8fd9\u79cd\u91cd\u590d\u5b50\u96c6<\/p>\n<hr \/>\n<h4>\u2705 \u2461 \u7ec8\u6b62\u6761\u4ef6&#xff08;\u5b50\u96c6\u7684\u201c\u7279\u6b8a\u70b9\u201d&#xff09;<\/h4>\n<p>if (startIndex &gt;&#061; nums.size()) return;<\/p>\n<p>\u8fd9\u91cc\u7684\u7ec8\u6b62\u6761\u4ef6\u975e\u5e38\u5f31&#xff0c;\u539f\u56e0\u662f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e0d\u9760\u7ec8\u6b62\u6761\u4ef6\u6536\u96c6\u7ed3\u679c<\/p>\n<\/li>\n<li>\n<p>\u6536\u96c6\u7ed3\u679c\u53d1\u751f\u5728\u201c\u8fdb\u5165\u51fd\u6570\u7684\u7b2c\u4e00\u884c\u201d<\/p>\n<\/li>\n<\/ul>\n<p>\u53ea\u8981 startIndex \u8d8a\u754c&#xff0c;\u5c31\u6ca1\u6cd5\u7ee7\u7eed\u9009\u4e86&#xff0c;\u76f4\u63a5\u8fd4\u56de\u5373\u53ef\u3002<\/p>\n<hr \/>\n<h4>\u2705 \u2462 \u5355\u5c42\u641c\u7d22\u903b\u8f91<\/h4>\n<p>for (int i &#061; startIndex; i &lt; nums.size(); i&#043;&#043;) {<br \/>\n    sub.push_back(nums[i]);<br \/>\n    backtracking(nums, i &#043; 1);<br \/>\n    sub.pop_back();<br \/>\n}<\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5728\u5f53\u524d\u5c42&#xff0c;\u4ece startIndex \u5f00\u59cb<\/p>\n<\/li>\n<li>\n<p>\u4f9d\u6b21\u5c1d\u8bd5\u628a\u6bcf\u4e2a\u5143\u7d20\u52a0\u5165\u5b50\u96c6<\/p>\n<\/li>\n<li>\n<p>\u7136\u540e\u9012\u5f52\u5411\u4e0b\u6269\u5c55<\/p>\n<\/li>\n<\/ul>\n<p>class Solution {<br \/>\npublic:<br \/>\n    vector&lt;vector&lt;int&gt;&gt;result;<br \/>\n    vector&lt;int&gt;sub;<\/p>\n<p>    void backtracking(vector&lt;int&gt;&amp;nums,int startIndex){<br \/>\n        result.push_back(sub);<br \/>\n        if(startIndex&gt;&#061;nums.size())return;<br \/>\n        for(int i&#061; startIndex;i&lt;nums.size();i&#043;&#043;){<br \/>\n            sub.push_back(nums[i]);<br \/>\n            backtracking(nums,i&#043;1);<br \/>\n            sub.pop_back();<br \/>\n        }<\/p>\n<p>    }<\/p>\n<p>    vector&lt;vector&lt;int&gt;&gt; subsets(vector&lt;int&gt;&amp; nums) {<br \/>\n        result.clear();<br \/>\n        sub.clear();<br \/>\n        backtracking(nums, 0);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>491. \u975e\u9012\u51cf\u5b50\u5e8f\u5217<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6574\u6570\u6570\u7ec4 nums&#xff0c;\u627e\u51fa\u6240\u6709\u9012\u589e\u5b50\u5e8f\u5217&#xff08;\u957f\u5ea6 \u2265 2&#xff09;&#xff0c;\u5b50\u5e8f\u5217\u4e0d\u8981\u6c42\u8fde\u7eed&#xff0c;\u4f46\u7ed3\u679c\u4e0d\u80fd\u91cd\u590d\u3002<\/p>\n<p>\u5173\u952e\u8bcd\u62c6\u89e3&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5b50\u5e8f\u5217&#xff1a;\u4e0d\u8981\u6c42\u8fde\u7eed \u2192 \u56de\u6eaf<\/p>\n<\/li>\n<li>\n<p>\u9012\u589e&#xff1a;\u6709\u987a\u5e8f\u7ea6\u675f<\/p>\n<\/li>\n<li>\n<p>\u6240\u6709\u65b9\u6848&#xff1a;\u4e0d\u662f\u6c42\u4e2a\u6570&#xff0c;\u662f\u6c42\u5217\u8868<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u91cd\u590d&#xff1a;\u8fd9\u662f\u96be\u70b9<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u4e00\u53e5\u8bdd\u5224\u65ad&#xff1a;<\/p>\n<p>\u8fd9\u662f\u201c\u5b50\u96c6\u7c7b\u56de\u6eaf &#043; \u987a\u5e8f\u7ea6\u675f &#043; \u53bb\u91cd\u201d\u7684\u7efc\u5408\u9898<\/p>\n<h3>\u628a\u95ee\u9898\u62bd\u8c61\u6210\u4e00\u68f5\u6811&#xff08;\u975e\u5e38\u5173\u952e&#xff09;<\/h3>\n<p>\u4ee5 nums &#061; [4,6,7,7] \u4e3a\u4f8b&#xff1a;<\/p>\n<p>                     []<br \/>\n          \/           |            \\\\<br \/>\n        [4]          [6]           [7]<br \/>\n      \/    \\\\           |              |<br \/>\n   [4,6]  [4,7]      [6,7]          [7,7]<br \/>\n      |       |<br \/>\n   [4,6,7] [4,7,7]<\/p>\n<h4>\u6811\u7ed3\u6784\u91cc\u7684\u9650\u5236<\/h4>\n<p>1\ufe0f\u20e3 \u4e0d\u80fd\u4e0b\u964d<\/p>\n<ul>\n<li>\n<p>\u540e\u9009\u7684\u6570\u5fc5\u987b \u2265 \u524d\u4e00\u4e2a\u6570<\/p>\n<\/li>\n<\/ul>\n<p>2\ufe0f\u20e3 \u540c\u4e00\u5c42\u4e0d\u80fd\u9009\u76f8\u540c\u7684\u6570<\/p>\n<ul>\n<li>\n<p>\u5426\u5219\u4f1a\u4ea7\u751f\u91cd\u590d\u5b50\u5e8f\u5217<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u96be\u70b9\u4e0d\u5728\u201c\u56de\u6eaf\u201d&#xff0c;\u800c\u5728**\u201c\u540c\u5c42\u53bb\u91cd\u201d**<\/p>\n<hr \/>\n<h3 style=\"background-color:transparent\">\u8fd9\u9053\u9898\u7684\u4e09\u5927\u6838\u5fc3\u7ea6\u675f<\/h3>\n<h4>\u2705 1\ufe0f\u20e3 \u5b50\u5e8f\u5217 \u2260 \u5b50\u96c6<\/h4>\n<ul>\n<li>\n<p>\u5b50\u96c6&#xff1a;\u5143\u7d20\u9009 or \u4e0d\u9009<\/p>\n<\/li>\n<li>\n<p>\u5b50\u5e8f\u5217&#xff1a;\u8981\u4fdd\u6301\u539f\u6570\u7ec4\u7684\u76f8\u5bf9\u987a\u5e8f<\/p>\n<\/li>\n<\/ul>\n<p>\u6240\u4ee5&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u53ea\u80fd\u4ece startIndex \u5f80\u540e\u9009<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u80fd\u56de\u5934<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2705 2\ufe0f\u20e3 \u9012\u589e\u7ea6\u675f&#xff08;\u7eb5\u5411\u7ea6\u675f&#xff09;<\/h4>\n<p>nums[i] &gt;&#061; path.back()<\/p>\n<p>\u5982\u679c\u5f53\u524d\u6570\u6bd4\u8def\u5f84\u6700\u540e\u4e00\u4e2a\u5c0f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fd9\u6761\u5206\u652f\u76f4\u63a5\u975e\u6cd5<\/p>\n<\/li>\n<li>\n<p>\u5fc5\u987b\u526a\u6389<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2705 3\ufe0f\u20e3 \u53bb\u91cd\u7ea6\u675f&#xff08;\u6a2a\u5411\u7ea6\u675f&#xff0c;\u6700\u5bb9\u6613\u9519&#xff09;<\/h4>\n<p>\u540c\u4e00\u5c42\u9012\u5f52\u4e2d&#xff0c;\u76f8\u540c\u7684\u6570\u5b57\u53ea\u80fd\u7528\u4e00\u6b21<\/p>\n<p>\u5426\u5219\u4f1a\u51fa\u73b0\u91cd\u590d\u7ed3\u679c&#xff0c;\u6bd4\u5982&#xff1a;<\/p>\n<p>[7]&#xff08;\u9009\u7b2c\u4e00\u4e2a 7&#xff09; [7]&#xff08;\u9009\u7b2c\u4e8c\u4e2a 7&#xff09; <\/p>\n<hr \/>\n<h3>\u56de\u6eaf\u4e09\u90e8\u66f2&#xff08;\u5bf9\u5e94\u672c\u9898&#xff09;<\/h3>\n<hr \/>\n<h4>\u2705 \u2460 \u56de\u6eaf\u51fd\u6570\u53c2\u6570<\/h4>\n<p>void backtracking(vector&lt;int&gt;&amp; nums, int startIndex)<\/p>\n<ul>\n<li>\n<p>startIndex&#xff1a;\u4fdd\u8bc1\u5b50\u5e8f\u5217\u987a\u5e8f<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u9700\u8981 target \/ sum<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u4e3b\u8981\u9760 path<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2705 \u2461 \u6536\u96c6\u7ed3\u679c\u7684\u65f6\u673a&#xff08;\u975e\u5e38\u91cd\u8981&#xff09;<\/h4>\n<p>if (path.size() &gt; 1) { result.push_back(path); } <\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u53ea\u8981\u5f53\u524d\u8def\u5f84\u957f\u5ea6 \u2265 2<\/p>\n<\/li>\n<li>\n<p>\u5c31\u662f\u4e00\u4e2a\u5408\u6cd5\u9012\u589e\u5b50\u5e8f\u5217<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u9700\u8981\u7b49\u5230\u53f6\u5b50\u8282\u70b9<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u8fd9\u4e00\u70b9\u548c\u300c\u5b50\u96c6\u95ee\u9898\u300d\u975e\u5e38\u50cf<\/p>\n<hr \/>\n<h4>\u2705 \u2462 \u5355\u5c42\u641c\u7d22\u903b\u8f91&#xff08;\u6838\u5fc3&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u4ece startIndex \u5f00\u59cb\u904d\u5386<\/p>\n<\/li>\n<li>\n<p>\u540c\u65f6\u6ee1\u8db3&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9012\u589e\u6761\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u540c\u5c42\u53bb\u91cd\u6761\u4ef6<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>class Solution {<br \/>\npublic:<br \/>\n    vector&lt;vector&lt;int&gt;&gt;result;<br \/>\n    vector&lt;int&gt;path;<\/p>\n<p>    void backtracking(vector&lt;int&gt;&amp; nums,int startIndex){<br \/>\n        if(path.size()&gt;1){<br \/>\n            result.push_back(path);<br \/>\n        }<br \/>\n        int set[201]&#061;{0};<br \/>\n        for(int i &#061; startIndex;i&lt;nums.size();i&#043;&#043;){<br \/>\n            if ((!path.empty() &amp;&amp; nums[i] &lt; path.back())<br \/>\n                    || set[nums[i] &#043; 100] &#061;&#061; 1) {<br \/>\n                    continue;<br \/>\n            }<br \/>\n            path.push_back(nums[i]);<br \/>\n            set[nums[i] &#043; 100] &#061; 1;<br \/>\n            backtracking(nums,i&#043;1);<br \/>\n            path.pop_back();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    vector&lt;vector&lt;int&gt;&gt; findSubsequences(vector&lt;int&gt;&amp; nums) {<br \/>\n        result.clear();<br \/>\n        path.clear();<br \/>\n        backtracking(nums,0);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>46. \u5168\u6392\u5217<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u5b83\u7684\u6240\u6709\u5168\u6392\u5217\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;[1,2,3]<\/p>\n<p>[1,2,3]<br \/>\n[1,3,2]<br \/>\n[2,1,3]<br \/>\n[2,3,1]<br \/>\n[3,1,2]<br \/>\n[3,2,1]<\/p>\n<h4>\u6392\u5217\u95ee\u9898\u7684\u201c\u672c\u8d28\u7279\u5f81\u201d<\/h4>\n<p>\u987a\u5e8f\u654f\u611f \u2757 \u8fd9\u548c\u524d\u9762\u7684\u9898\u6709\u672c\u8d28\u533a\u522b&#xff1a;<\/p>\n<ul>\n<li>\n<p>[1,2] \u548c [2,1] \u662f \u4e24\u4e2a\u4e0d\u540c\u89e3<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u4e2a\u4f4d\u7f6e\u90fd\u8981\u5c1d\u8bd5\u6240\u6709\u8fd8\u6ca1\u7528\u8fc7\u7684\u6570<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u4e00\u53e5\u8bdd\u5224\u65ad&#xff1a;<\/p>\n<p>\u201c\u987a\u5e8f\u4f1a\u4ea7\u751f\u4e0d\u540c\u7ed3\u679c\u201d \u2192 \u6392\u5217 \u2192 \u4e00\u5b9a\u8981\u7528 used \u6570\u7ec4<\/p>\n<hr \/>\n<h3>\u628a\u6392\u5217\u95ee\u9898\u62bd\u8c61\u6210\u4e00\u68f5\u6811&#xff08;\u975e\u5e38\u5173\u952e&#xff09;<\/h3>\n<p>\u4ee5 nums &#061; [1,2,3] \u4e3a\u4f8b&#xff1a;<\/p>\n<p>                   []<br \/>\n        \/              |               \\\\<br \/>\n      [1]             [2]              [3]<br \/>\n   \/       \\\\        \/       \\\\        \/       \\\\<br \/>\n[1,2]   [1,3]   [2,1]   [2,3]   [3,1]   [3,2]<br \/>\n   |        |       |        |       |        |<br \/>\n[1,2,3][1,3,2][2,1,3][2,3,1][3,1,2][3,2,1]<\/p>\n<h4>\u6811\u7ed3\u6784\u542b\u4e49<\/h4>\n<table>\n<tr>\u56de\u6eaf\u6982\u5ff5\u672c\u9898\u542b\u4e49<\/tr>\n<tbody>\n<tr>\n<td>\u6811\u7684\u6df1\u5ea6<\/td>\n<td>path.size()<\/td>\n<\/tr>\n<tr>\n<td>\u6bcf\u4e00\u5c42<\/td>\n<td>\u51b3\u5b9a\u201c\u5f53\u524d\u7b2c\u51e0\u4e2a\u4f4d\u7f6e\u653e\u8c01\u201d<\/td>\n<\/tr>\n<tr>\n<td>\u6bcf\u4e00\u5c42\u53ef\u9009<\/td>\n<td>\u6240\u6709\u8fd8\u6ca1\u7528\u8fc7\u7684\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td>\u53f6\u5b50\u8282\u70b9<\/td>\n<td>path.size() &#061;&#061; nums.size()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u56de\u6eaf\u4e09\u90e8\u66f2&#xff08;\u5bf9\u5e94\u672c\u9898&#xff09;<\/h3>\n<hr \/>\n<h4>\u2705 \u2460 \u56de\u6eaf\u51fd\u6570\u53c2\u6570<\/h4>\n<p>void backtracking(vector&lt;int&gt;&amp; nums, vector&lt;bool&gt;&amp; used) <\/p>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981 used&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u5728\u6392\u5217\u4e2d&#xff1a;<\/p>\n<p>\u6bcf\u4e2a\u6570\u5b57\u53ea\u80fd\u7528\u4e00\u6b21&#xff0c;\u4f46\u6bcf\u4e00\u5c42\u90fd\u8981\u4ece 0 \u5f00\u59cb\u904d\u5386<\/p>\n<p>\u8fd9\u548c\u7ec4\u5408 \/ \u5b50\u96c6 \u5b8c\u5168\u4e0d\u540c\u3002<\/p>\n<hr \/>\n<h4>\u2705 \u2461 \u7ec8\u6b62\u6761\u4ef6&#xff08;\u4ec0\u4e48\u65f6\u5019\u6536\u96c6\u7ed3\u679c&#xff09;<\/h4>\n<p>if (path.size() &#061;&#061; nums.size()) { result.push_back(path); } <\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5f53\u524d\u8def\u5f84\u957f\u5ea6\u7b49\u4e8e\u6570\u7ec4\u957f\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u8bf4\u660e\u6bcf\u4e2a\u4f4d\u7f6e\u90fd\u5df2\u7ecf\u653e\u4e86\u4e00\u4e2a\u6570<\/p>\n<\/li>\n<li>\n<p>\u5f97\u5230\u4e00\u4e2a\u5b8c\u6574\u6392\u5217<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2705 \u2462 \u5355\u5c42\u641c\u7d22\u903b\u8f91&#xff08;\u6392\u5217\u7684\u6838\u5fc3&#xff09;<\/h4>\n<p>for (int i &#061; 0; i &lt; nums.size(); i&#043;&#043;) { <\/p>\n<p>\u6ce8\u610f\u8fd9\u91cc&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e0d\u662f\u4ece startIndex<\/p>\n<\/li>\n<li>\n<p>\u800c\u662f \u6bcf\u4e00\u5c42\u90fd\u4ece 0 \u5f00\u59cb<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f449; \u56e0\u4e3a\u6392\u5217\u7684\u6bcf\u4e00\u4e2a\u4f4d\u7f6e&#xff0c;\u90fd\u53ef\u4ee5\u653e\u4efb\u4f55\u8fd8\u6ca1\u7528\u8fc7\u7684\u6570\u3002<\/p>\n<p>class Solution {<br \/>\npublic:<br \/>\n    vector&lt;vector&lt;int&gt;&gt;result;<br \/>\n    vector&lt;int&gt;path;<br \/>\n    void backtracking(vector&lt;int&gt;&amp;nums,vector&lt;bool&gt;&amp;used){<br \/>\n       if(path.size()&#061;&#061;nums.size()){<br \/>\n            result.push_back(path);<br \/>\n            return;<br \/>\n       }<\/p>\n<p>        for(int i &#061; 0 ; i&lt;nums.size();i&#043;&#043;){<br \/>\n            if(used[i]&#061;&#061;true)continue;<br \/>\n            used[i]&#061;true;<br \/>\n            path.push_back(nums[i]);<br \/>\n            backtracking(nums,used);<br \/>\n            used[i]&#061;false;<br \/>\n            path.pop_back();<br \/>\n        }<\/p>\n<p>    }<\/p>\n<p>    vector&lt;vector&lt;int&gt;&gt; permute(vector&lt;int&gt;&amp; nums) {<br \/>\n        result.clear();<br \/>\n        path.clear();<br \/>\n        vector&lt;bool&gt;used(nums.size(),false);<br \/>\n        backtracking(nums,used);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>47. \u5168\u6392\u5217 II<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a \u53ef\u80fd\u5305\u542b\u91cd\u590d\u6570\u5b57 \u7684\u6570\u7ec4 nums&#xff0c;\u8fd4\u56de\u6240\u6709 \u4e0d\u91cd\u590d\u7684\u5168\u6392\u5217\u3002<\/p>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>nums &#061; [1,1,2]<\/p>\n<p>\u5408\u6cd5\u7ed3\u679c&#xff1a;<br \/>\n[1,1,2]<br \/>\n[1,2,1]<br \/>\n[2,1,1]<\/p>\n<p>\u975e\u6cd5&#xff08;\u91cd\u590d&#xff09;&#xff1a;<\/p>\n<p>[1,1,2]&#xff08;\u7528\u7b2c\u4e00\u4e2a1&#xff09;<br \/>\n[1,1,2]&#xff08;\u7528\u7b2c\u4e8c\u4e2a1&#xff09;<\/p>\n<h3>\u4e3a\u4ec0\u4e48\u201c\u666e\u901a\u6392\u5217 &#043; used[]\u201d\u4e0d\u591f&#xff1f;<\/h3>\n<p>\u5728 permute&#xff08;\u65e0\u91cd\u590d&#xff09; \u91cc&#xff1a;<\/p>\n<p>if (used[i]) continue;<\/p>\n<p>\u53ea\u80fd\u4fdd\u8bc1&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4e00\u4e2a\u5143\u7d20\u5728\u4e00\u6761\u6392\u5217\u91cc\u53ea\u7528\u4e00\u6b21<\/p>\n<\/li>\n<\/ul>\n<p>\u274c \u4f46\u6321\u4e0d\u4f4f\u8fd9\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<p>nums &#061; [1,1,2]<\/p>\n<p>\u7b2c\u4e00\u5c42&#xff1a;<br \/>\n\u9009 nums[0] &#061; 1 \u2192 path &#061; [1]<br \/>\n\u9009 nums[1] &#061; 1 \u2192 path &#061; [1]   &#xff08;\u6570\u503c\u4e00\u6837&#xff0c;\u4f46\u4e0b\u6807\u4e0d\u540c&#xff09;<\/p>\n<p>&#x1f449; \u4e0b\u6807\u4e0d\u540c&#xff0c;\u4f46\u503c\u76f8\u540c &#x1f449; \u4f1a\u751f\u6210\u4e00\u6a21\u4e00\u6837\u7684\u6392\u5217<\/p>\n<p>\u6240\u4ee5&#xff1a; \u6392\u5217\u53bb\u91cd \u2260 \u9632\u6b62\u91cd\u590d\u4f7f\u7528\u5143\u7d20 \u800c\u662f&#xff1a;<\/p>\n<p>\u9632\u6b62\u5728\u540c\u4e00\u5c42&#xff0c;\u7528\u201c\u76f8\u540c\u7684\u503c\u201d\u5f00\u5934<\/p>\n<h3>\u6392\u5217\u53bb\u91cd\u7684\u6838\u5fc3\u601d\u60f3&#xff08;\u4e00\u53e5\u8bdd\u7248&#xff09;<\/h3>\n<p>\u76f8\u540c\u7684\u6570\u5b57&#xff0c;\u5fc5\u987b\u201c\u6309\u987a\u5e8f\u201d\u4f7f\u7528 \u524d\u4e00\u4e2a\u6ca1\u7528&#xff0c;\u540e\u4e00\u4e2a\u4e0d\u80fd\u7528<\/p>\n<p>\u8fd9\u53e5\u8bdd\u5c31\u662f\u4e0b\u9762\u8fd9\u884c\u4ee3\u7801\u7684\u6570\u5b66\u542b\u4e49&#xff1a;<\/p>\n<p>if (i &gt; 0 &amp;&amp; nums[i] &#061;&#061; nums[i &#8211; 1] &amp;&amp; used[i &#8211; 1] &#061;&#061; false)<\/p>\n<p>if (<br \/>\n    i &gt; 0<br \/>\n    &amp;&amp; nums[i] &#061;&#061; nums[i &#8211; 1]<br \/>\n    &amp;&amp; used[i &#8211; 1] &#061;&#061; false<br \/>\n) {<br \/>\n    continue;<br \/>\n}<\/p>\n<p>\u7ffb\u8bd1\u6210\u4e00\u53e5\u4eba\u8bdd&#xff1a;<\/p>\n<p>\u5982\u679c\u5f53\u524d\u6570\u5b57\u548c\u524d\u4e00\u4e2a\u6570\u5b57\u76f8\u540c&#xff0c; \u4e14\u524d\u4e00\u4e2a\u6570\u5b57\u5728\u5f53\u524d\u6811\u679d\u4e2d\u8fd8\u6ca1\u88ab\u7528\u8fc7&#xff0c; \u90a3\u8bf4\u660e\u6211\u6b63\u7ad9\u5728\u201c\u540c\u4e00\u5c42\u201d&#xff0c; \u8fd9\u4e2a\u5206\u652f\u4e00\u5b9a\u4f1a\u4ea7\u751f\u91cd\u590d\u6392\u5217&#xff0c;\u5fc5\u987b\u8df3\u8fc7\u3002<\/p>\n<p>class Solution {<br \/>\nprivate:<br \/>\n    vector&lt;vector&lt;int&gt;&gt; result;<br \/>\n    vector&lt;int&gt; path;<br \/>\n    void backtracking (vector&lt;int&gt;&amp; nums, vector&lt;bool&gt;&amp; used) {<br \/>\n        \/\/ \u6b64\u65f6\u8bf4\u660e\u627e\u5230\u4e86\u4e00\u7ec4<br \/>\n        if (path.size() &#061;&#061; nums.size()) {<br \/>\n            result.push_back(path);<br \/>\n            return;<br \/>\n        }<br \/>\n        for (int i &#061; 0; i &lt; nums.size(); i&#043;&#043;) {<br \/>\n            \/\/ used[i &#8211; 1] &#061;&#061; true&#xff0c;\u8bf4\u660e\u540c\u4e00\u6811\u679dnums[i &#8211; 1]\u4f7f\u7528\u8fc7<br \/>\n            \/\/ used[i &#8211; 1] &#061;&#061; false&#xff0c;\u8bf4\u660e\u540c\u4e00\u6811\u5c42nums[i &#8211; 1]\u4f7f\u7528\u8fc7<br \/>\n            \/\/ \u5982\u679c\u540c\u4e00\u6811\u5c42nums[i &#8211; 1]\u4f7f\u7528\u8fc7\u5219\u76f4\u63a5\u8df3\u8fc7<br \/>\n            if (i &gt; 0 &amp;&amp; nums[i] &#061;&#061; nums[i &#8211; 1] &amp;&amp; used[i &#8211; 1] &#061;&#061; false) {<br \/>\n                continue;<br \/>\n            }<br \/>\n            if (used[i] &#061;&#061; false) {<br \/>\n                used[i] &#061; true;<br \/>\n                path.push_back(nums[i]);<br \/>\n                backtracking(nums, used);<br \/>\n                path.pop_back();<br \/>\n                used[i] &#061; false;<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\npublic:<br \/>\n    vector&lt;vector&lt;int&gt;&gt; permuteUnique(vector&lt;int&gt;&amp; nums) {<br \/>\n        result.clear();<br \/>\n        path.clear();<br \/>\n        sort(nums.begin(), nums.end()); \/\/ \u6392\u5e8f<br \/>\n        vector&lt;bool&gt; used(nums.size(), false);<br \/>\n        backtracking(nums, used);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>51. N \u7687\u540e<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u5728\u4e00\u4e2a n \u00d7 n \u7684\u68cb\u76d8\u4e0a&#xff0c;\u653e\u7f6e n \u4e2a\u7687\u540e&#xff0c;\u4f7f\u5f97\u5b83\u4eec\u4e92\u4e0d\u653b\u51fb&#xff0c;\u8fd4\u56de\u6240\u6709\u4e0d\u540c\u7684\u6446\u653e\u65b9\u6848\u3002<\/p>\n<h4>\u7687\u540e\u7684\u653b\u51fb\u89c4\u5219<\/h4>\n<p>\u4e00\u4e2a\u7687\u540e\u4f1a\u653b\u51fb&#xff1a;<\/p>\n<li>\n<p>\u540c\u4e00\u5217<\/p>\n<\/li>\n<li>\n<p>\u5de6\u4e0a \u2196 \u53f3\u4e0b \u2198 \u5bf9\u89d2\u7ebf<\/p>\n<\/li>\n<li>\n<p>\u53f3\u4e0a \u2197 \u5de6\u4e0b \u2199 \u5bf9\u89d2\u7ebf<\/p>\n<\/li>\n<p>&#x1f449; \u884c\u4e0d\u7528\u68c0\u67e5&#xff0c;\u56e0\u4e3a\u6211\u4eec\u4fdd\u8bc1\u6bcf\u4e00\u884c\u53ea\u653e\u4e00\u4e2a\u7687\u540e<\/p>\n<h3>N \u7687\u540e &#061; \u5178\u578b\u201c\u68cb\u76d8\u578b\u56de\u6eaf\u201d<\/h3>\n<p>\u8fd9\u7c7b\u9898\u7684\u56fa\u5b9a\u5957\u8def\u662f&#xff1a;<\/p>\n<p>\u4e00\u884c\u4e00\u884c\u653e\u7687\u540e&#xff0c;\u6bcf\u4e00\u884c\u9009\u62e9\u4e00\u4e2a\u5408\u6cd5\u7684\u5217<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6811\u7684\u6df1\u5ea6 &#061; \u884c\u53f7 row<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u5c42\u7684\u9009\u62e9 &#061; \u8fd9\u4e00\u884c\u7687\u540e\u653e\u5728\u54ea\u4e00\u5217 col<\/p>\n<\/li>\n<li>\n<p>\u4e00\u4e2a\u5b8c\u6574\u89e3 &#061; \u6210\u529f\u653e\u5b8c\u7b2c n \u884c<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u628a\u95ee\u9898\u62bd\u8c61\u6210\u4e00\u68f5\u6811&#xff08;\u5173\u952e\u7406\u89e3&#xff09;<\/h3>\n<p>\u4ee5 n &#061; 4 \u4e3a\u4f8b&#xff1a;<\/p>\n<p>\u7b2c 0 \u884c&#xff1a;col &#061; 0 \/ 1 \/ 2 \/ 3<br \/>\n   \u2193<br \/>\n\u7b2c 1 \u884c&#xff1a;\u5728\u5408\u6cd5\u5217\u4e2d\u9009<br \/>\n   \u2193<br \/>\n\u7b2c 2 \u884c&#xff1a;\u7ee7\u7eed\u9009<br \/>\n   \u2193<br \/>\n\u7b2c 3 \u884c&#xff1a;\u7ee7\u7eed\u9009<br \/>\n   \u2193<br \/>\nrow &#061;&#061; n \u2192 \u5f97\u5230\u4e00\u4e2a\u89e3<\/p>\n<p>&#x1f449; \u6bcf\u4e00\u5c42\u53ea\u5173\u5fc3\u201c\u8fd9\u4e00\u884c\u7687\u540e\u80fd\u653e\u5728\u54ea\u201d<\/p>\n<hr \/>\n<h3>\u6574\u4f53\u89e3\u6cd5\u62c6\u6210\u4e24\u90e8\u5206<\/h3>\n<h4>\u2705 \u7b2c\u4e00\u90e8\u5206&#xff1a;\u5408\u6cd5\u6027\u5224\u65ad isValid<\/h4>\n<p>\u5224\u65ad&#xff1a;<\/p>\n<p>\u5728 (row, col) \u653e\u7687\u540e&#xff0c;\u662f\u5426\u4f1a\u548c\u524d\u9762\u5df2\u7ecf\u653e\u7684\u7687\u540e\u51b2\u7a81<\/p>\n<p>\u26a0\ufe0f \u53ea\u9700\u8981\u68c0\u67e5 row \u4e4b\u524d\u7684\u884c \u56e0\u4e3a\u540e\u9762\u7684\u884c\u8fd8\u6ca1\u653e\u3002<\/p>\n<hr \/>\n<h4>\u2705 \u7b2c\u4e8c\u90e8\u5206&#xff1a;\u56de\u6eaf\u653e\u7687\u540e<\/h4>\n<ul>\n<li>\n<p>\u4ece\u7b2c 0 \u884c\u5f00\u59cb<\/p>\n<\/li>\n<li>\n<p>\u6bcf\u4e00\u884c\u5c1d\u8bd5\u6240\u6709\u5217<\/p>\n<\/li>\n<li>\n<p>\u653e\u5f97\u4e0b\u5c31\u9012\u5f52\u5230\u4e0b\u4e00\u884c<\/p>\n<\/li>\n<li>\n<p>\u653e\u4e0d\u4e0b\u5c31\u6362\u5217<\/p>\n<\/li>\n<li>\n<p>\u884c\u53f7\u5230 n&#xff0c;\u6536\u96c6\u7ed3\u679c<\/p>\n<\/li>\n<\/ul>\n<p>class Solution {<br \/>\npublic:<br \/>\n    vector&lt;vector&lt;string&gt;&gt; result;<br \/>\n    bool isValid(int row,int col,vector&lt;string&gt;&amp; chessboard,int n){<br \/>\n        for(int i&#061;0;i&lt;row;i&#043;&#043;){<br \/>\n            if(chessboard[i][col]&#061;&#061;&#039;Q&#039;)return false;<br \/>\n        }<br \/>\n        for(int i &#061; row-1,j&#061;col-1;i&gt;&#061;0 &amp;&amp; j&gt;&#061;0;i&#8211;,j&#8211;){<br \/>\n            if(chessboard[i][j]&#061;&#061;&#039;Q&#039;)return false;<br \/>\n        }<br \/>\n        for(int i &#061; row-1,j&#061;col&#043;1;i&gt;&#061;0 &amp;&amp; j&lt;n;i&#8211;,j&#043;&#043;){<br \/>\n            if(chessboard[i][j]&#061;&#061;&#039;Q&#039;)return false;<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<br \/>\n    void backtracking(int n,int row,vector&lt;string&gt;&amp;chessboard){<br \/>\n        if(row &#061;&#061; n){<br \/>\n            result.push_back(chessboard);<br \/>\n            return;<br \/>\n        }<\/p>\n<p>        for(int col &#061; 0; col&lt;n;col&#043;&#043;){<br \/>\n            if(isValid(row,col,chessboard,n)){<br \/>\n                chessboard[row][col]&#061;&#039;Q&#039;;<br \/>\n                backtracking(n,row&#043;1,chessboard);<br \/>\n                chessboard[row][col]&#061;&#039;.&#039;;<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    vector&lt;vector&lt;string&gt;&gt; solveNQueens(int n) {<br \/>\n        result.clear();<br \/>\n        vector&lt;string&gt;chessboard(n,string(n,&#039;.&#039;));<br \/>\n        backtracking(n,0,chessboard);<br \/>\n        return result;<br \/>\n    }<br \/>\n}; <\/p>\n<h2>37. \u89e3\u6570\u72ec<\/h2>\n<h3>\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<\/h3>\n<p>\u9898\u76ee\u8981\u6c42&#xff1a;<\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a 9\u00d79 \u7684\u6570\u72ec\u68cb\u76d8&#xff08;\u90e8\u5206\u5df2\u586b&#xff09;&#xff0c;\u586b\u6ee1\u6574\u4e2a\u68cb\u76d8&#xff0c;\u4f7f\u5176\u6ee1\u8db3\u6570\u72ec\u89c4\u5219\u3002<\/p>\n<h4>\u6570\u72ec\u89c4\u5219&#xff08;\u4e09\u4e2a\u7ea6\u675f&#xff09;<\/h4>\n<p>\u5bf9\u6bcf\u4e2a\u6570\u5b57 &#039;1&#039;~&#039;9&#039;&#xff1a;<\/p>\n<li>\n<p>\u540c\u4e00\u884c\u4e0d\u80fd\u91cd\u590d<\/p>\n<\/li>\n<li>\n<p>\u540c\u4e00\u5217\u4e0d\u80fd\u91cd\u590d<\/p>\n<\/li>\n<li>\n<p>\u540c\u4e00\u4e2a 3\u00d73 \u5bab\u683c\u4e0d\u80fd\u91cd\u590d<\/p>\n<\/li>\n<hr \/>\n<h3>\u6570\u72ec &#061; \u68cb\u76d8\u56de\u6eaf &#043; \u201c\u627e\u5230\u4e00\u4e2a\u89e3\u5c31\u505c\u201d<\/h3>\n<p>\u8fd9\u662f\u6570\u72ec\u548c N \u7687\u540e\u6700\u5927\u7684\u4e0d\u540c&#xff1a;<\/p>\n<table>\n<tr>\u9898\u76ee\u8981\u4e0d\u8981\u6240\u6709\u89e3<\/tr>\n<tbody>\n<tr>\n<td>N \u7687\u540e<\/td>\n<td>\u8981\u6240\u6709\u65b9\u6848<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u72ec<\/td>\n<td>\u53ea\u8981\u4e00\u4e2a\u89e3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f449; \u6240\u4ee5\u6570\u72ec\u7684\u56de\u6eaf\u51fd\u6570 \u5fc5\u987b\u8fd4\u56de bool &#x1f449; \u4e00\u65e6\u627e\u5230\u5408\u6cd5\u89e3&#xff0c;\u7acb\u523b\u505c\u6b62\u641c\u7d22<\/p>\n<hr \/>\n<h3>\u6574\u4f53\u56de\u6eaf\u7b56\u7565&#xff08;\u975e\u5e38\u5173\u952e&#xff09;<\/h3>\n<h4>\u6838\u5fc3\u601d\u60f3\u4e00\u53e5\u8bdd&#xff1a;<\/h4>\n<p>\u6bcf\u6b21\u627e\u4e00\u4e2a\u7a7a\u683c &#039;.&#039;&#xff0c;\u5c1d\u8bd5\u586b 1~9&#xff0c;\u80fd\u586b\u5c31\u7ee7\u7eed&#xff0c;\u586b\u4e0d\u4e0b\u5c31\u56de\u9000<\/p>\n<hr \/>\n<h4>\u641c\u7d22\u987a\u5e8f\u662f\u8fd9\u6837\u7684&#xff1a;<\/h4>\n<li>\n<p>\u4ece\u5de6\u5230\u53f3\u3001\u4ece\u4e0a\u5230\u4e0b\u626b\u63cf\u68cb\u76d8<\/p>\n<\/li>\n<li>\n<p>\u627e\u5230\u7b2c\u4e00\u4e2a &#039;.&#039;<\/p>\n<\/li>\n<li>\n<p>\u5c1d\u8bd5\u586b &#039;1&#039;~&#039;9&#039;<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u5408\u6cd5&#xff0c;\u9012\u5f52\u586b\u4e0b\u4e00\u4e2a\u7a7a\u683c<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u540e\u9762\u5931\u8d25&#xff0c;\u64a4\u9500\u5f53\u524d\u586b\u5199&#xff0c;\u6362\u4e0b\u4e00\u4e2a\u6570\u5b57<\/p>\n<\/li>\n<h3>\u56de\u6eaf\u51fd\u6570 backtracking \u8be6\u89e3<\/h3>\n<p>bool backtracking(vector&lt;vector&lt;char&gt;&gt;&amp; board) <\/p>\n<p>&#x1f449; \u8fd4\u56de\u503c\u542b\u4e49\u975e\u5e38\u91cd\u8981&#xff1a;<\/p>\n<ul>\n<li>\n<p>true&#xff1a;\u5df2\u7ecf\u627e\u5230\u4e00\u4e2a\u5b8c\u6574\u5408\u6cd5\u89e3<\/p>\n<\/li>\n<li>\n<p>false&#xff1a;\u5f53\u524d\u8def\u5f84\u4e0d\u884c&#xff0c;\u9700\u8981\u56de\u6eaf<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2460 \u627e\u201c\u5f53\u524d\u8981\u586b\u7684\u683c\u5b50\u201d<\/h4>\n<p>for (int i &#061; 0; i &lt; board.size(); i&#043;&#043;) <\/p>\n<p>{ for (int j &#061; 0; j &lt; board.size(); j&#043;&#043;) <\/p>\n<p>{ if (board[i][j] &#061;&#061; &#039;.&#039;) { <\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6309\u987a\u5e8f\u626b\u63cf\u68cb\u76d8<\/p>\n<\/li>\n<li>\n<p>\u627e\u5230\u7b2c\u4e00\u4e2a\u7a7a\u683c<\/p>\n<\/li>\n<li>\n<p>\u53ea\u5904\u7406\u8fd9\u4e00\u4e2a\u7a7a\u683c<\/p>\n<\/li>\n<\/ul>\n<p>\u26a0\ufe0f \u6ce8\u610f&#xff1a; \u4e00\u65e6\u627e\u5230 &#039;.&#039;&#xff0c;\u540e\u9762\u7684\u683c\u5b50\u6682\u65f6\u4e0d\u7ba1<\/p>\n<h4>\u2461 \u5c1d\u8bd5\u586b &#039;1&#039; ~ &#039;9&#039;<\/h4>\n<p>for (char k &#061; &#039;1&#039;; k &lt;&#061; &#039;9&#039;; k&#043;&#043;) { <\/p>\n<p>\u6bcf\u4e00\u4e2a k&#xff0c;\u90fd\u662f\u4e00\u4e2a\u201c\u9009\u62e9\u201d\u3002<\/p>\n<hr \/>\n<h4>\u2462 \u5408\u6cd5\u6027\u5224\u65ad&#xff08;\u526a\u679d&#xff09;<\/h4>\n<p>if (isValid(i, j, k, board)) { <\/p>\n<ul>\n<li>\n<p>\u4e0d\u5408\u6cd5 \u2192 \u76f4\u63a5\u8df3\u8fc7<\/p>\n<\/li>\n<li>\n<p>\u5408\u6cd5 \u2192 \u5c1d\u8bd5\u586b\u5165<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h4>\u2463 \u505a\u9009\u62e9 &#043; \u9012\u5f52<\/h4>\n<p>board[i][j] &#061; k; if (backtracking(board)) return true; board[i][j] &#061; &#039;.&#039;; <\/p>\n<p>\u8fd9\u662f\u6570\u72ec\u56de\u6eaf\u7684\u7075\u9b42\u4e09\u884c&#xff1a;<\/p>\n<h5>\u53d1\u751f\u4e86\u4ec0\u4e48&#xff1f;<\/h5>\n<li>\n<p>\u5c1d\u8bd5\u586b k<\/p>\n<\/li>\n<li>\n<p>\u9012\u5f52\u586b\u540e\u7eed\u7a7a\u683c<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u540e\u9762\u6210\u529f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u76f4\u63a5\u4e00\u8def return true<\/p>\n<\/li>\n<li>\n<p>\u6574\u4e2a\u641c\u7d22\u7ec8\u6b62<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5982\u679c\u540e\u9762\u5931\u8d25&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u56de\u6eaf&#xff0c;\u64a4\u9500 k<\/p>\n<\/li>\n<li>\n<p>\u5c1d\u8bd5\u4e0b\u4e00\u4e2a\u6570\u5b57<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<hr \/>\n<h4>\u2464 \u4e3a\u4ec0\u4e48\u8fd9\u91cc\u8981 return false&#xff1f;<\/h4>\n<p>return false; <\/p>\n<p>\u4f4d\u7f6e\u5f88\u5173\u952e&#xff0c;\u5728\u8fd9\u91cc&#xff1a;<\/p>\n<p>if (board[i][j] &#061;&#061; &#039;.&#039;) { &#8230; return false; } <\/p>\n<p>\u542b\u4e49\u662f&#xff1a;<\/p>\n<p>\u8fd9\u4e2a\u7a7a\u683c&#xff0c;1~9 \u5168\u90e8\u8bd5\u8fc7\u4e86&#xff0c;\u90fd\u4e0d\u884c \u90a3\u8bf4\u660e\u4e4b\u524d\u7684\u67d0\u4e00\u6b65\u9009\u9519\u4e86&#xff0c;\u5fc5\u987b\u56de\u6eaf<\/p>\n<hr \/>\n<h4>\u2465 \u4ec0\u4e48\u65f6\u5019\u8fd4\u56de true&#xff1f;<\/h4>\n<p>return true; <\/p>\n<p>\u5728\u51fd\u6570\u6700\u540e&#xff1a;<\/p>\n<p>return true; <\/p>\n<p>\u542b\u4e49&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u626b\u63cf\u5b8c\u6574\u4e2a\u68cb\u76d8<\/p>\n<\/li>\n<li>\n<p>\u6ca1\u6709\u627e\u5230\u4efb\u4f55 &#039;.&#039;<\/p>\n<\/li>\n<li>\n<p>\u8bf4\u660e\u6574\u4e2a\u68cb\u76d8\u5df2\u7ecf\u5408\u6cd5\u586b\u6ee1<\/p>\n<\/li>\n<li>\n<p>\u627e\u5230\u4e00\u4e2a\u89e3 \u2714<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e94\u3001\u5408\u6cd5\u6027\u5224\u65ad isValid \u9010\u6bb5\u8bb2\u89e3<\/h3>\n<p>bool isValid(int row, int col, char k, vector&lt;vector&lt;char&gt;&gt;&amp; board) <\/p>\n<hr \/>\n<h4>\u2460 \u68c0\u67e5\u884c<\/h4>\n<p>for (int i &#061; 0; i &lt; 9; i&#043;&#043;) { if (board[row][i] &#061;&#061; k) return false; } <\/p>\n<hr \/>\n<h4>\u2461 \u68c0\u67e5\u5217<\/h4>\n<p>for (int j &#061; 0; j &lt; 9; j&#043;&#043;) { if (board[j][col] &#061;&#061; k) return false; } <\/p>\n<hr \/>\n<h4>\u2462 \u68c0\u67e5 3\u00d73 \u5bab\u683c<\/h4>\n<p>int startrow &#061; (row \/ 3) * 3;<br \/>\nint startcol &#061; (col \/ 3) * 3;<\/p>\n<p>for (int i &#061; startrow; i &lt; startrow &#043; 3; i&#043;&#043;) {<br \/>\n    for (int j &#061; startcol; j &lt; startcol &#043; 3; j&#043;&#043;) {<br \/>\n        if (board[i][j] &#061;&#061; k) return false;<br \/>\n    }<br \/>\n}<\/p>\n<p>&#x1f449; (row\/3)*3 \u662f\u5b9a\u4f4d\u5bab\u683c\u5de6\u4e0a\u89d2\u7684\u6807\u51c6\u6280\u5de7<\/p>\n<hr \/>\n<h3>\u516d\u3001\u6570\u72ec vs N \u7687\u540e&#xff08;\u672c\u8d28\u5dee\u5f02&#xff09;<\/h3>\n<p>\u8fd9\u662f\u975e\u5e38\u91cd\u8981\u7684\u5bf9\u6bd4&#xff1a;<\/p>\n<table>\n<tr>\u7ef4\u5ea6N \u7687\u540e\u6570\u72ec<\/tr>\n<tbody>\n<tr>\n<td>\u641c\u7d22\u76ee\u6807<\/td>\n<td>\u6240\u6709\u89e3<\/td>\n<td>\u4efb\u610f\u4e00\u4e2a\u89e3<\/td>\n<\/tr>\n<tr>\n<td>\u56de\u6eaf\u8fd4\u56de\u503c<\/td>\n<td>void<\/td>\n<td>bool<\/td>\n<\/tr>\n<tr>\n<td>\u641c\u7d22\u987a\u5e8f<\/td>\n<td>\u6309\u884c<\/td>\n<td>\u6309\u7a7a\u683c<\/td>\n<\/tr>\n<tr>\n<td>\u526a\u679d\u4f9d\u636e<\/td>\n<td>\u653b\u51fb\u89c4\u5219<\/td>\n<td>\u884c \/ \u5217 \/ \u5bab<\/td>\n<\/tr>\n<tr>\n<td>\u627e\u5230\u89e3\u540e<\/td>\n<td>\u7ee7\u7eed<\/td>\n<td>\u7acb\u523b\u505c\u6b62<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>class Solution {<br \/>\npublic:<br \/>\n    bool backtracking(vector&lt;vector&lt;char&gt;&gt;&amp; board){<br \/>\n        for(int i &#061; 0;i&lt;board.size();i&#043;&#043;){<br \/>\n            for(int j&#061;0;j&lt;board.size();j&#043;&#043;){<br \/>\n                if(board[i][j]&#061;&#061;&#039;.&#039;){<br \/>\n                    for(char k&#061;&#039;1&#039;;k&lt;&#061;&#039;9&#039;;k&#043;&#043;){<br \/>\n                       if (isValid(i, j, k, board)) {<br \/>\n                        board[i][j] &#061; k;                \/\/ \u653e\u7f6ek<br \/>\n                        if (backtracking(board)) return true; \/\/ \u5982\u679c\u627e\u5230\u5408\u9002\u4e00\u7ec4\u7acb\u523b\u8fd4\u56de<br \/>\n                        board[i][j] &#061; &#039;.&#039;;              \/\/ \u56de\u6eaf&#xff0c;\u64a4\u9500k<br \/>\n                        }<br \/>\n                    }<br \/>\n                    return false;<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<\/p>\n<p>    bool isValid(int row ,int col,char k,vector&lt;vector&lt;char&gt;&gt;&amp;board){<br \/>\n        for(int i&#061;0;i&lt;9;i&#043;&#043;){<br \/>\n            if(board[row][i]&#061;&#061;k)return false;<br \/>\n        }<br \/>\n        for(int j &#061; 0;j&lt;9;j&#043;&#043;){<br \/>\n            if(board[j][col]&#061;&#061;k)return false;<br \/>\n        }<br \/>\n        int startrow &#061; (row\/3)*3;<br \/>\n        int statrcol &#061; (col\/3)*3;<br \/>\n        for(int i&#061;startrow;i&lt;startrow &#043; 3;i&#043;&#043;){<br \/>\n            for(int j&#061;statrcol;j&lt;statrcol&#043;3;j&#043;&#043;){<br \/>\n                if(board[i][j]&#061;&#061;k)return false;<br \/>\n            }<br \/>\n        }<br \/>\n        return true;<br \/>\n    }<\/p>\n<p>    void solveSudoku(vector&lt;vector&lt;char&gt;&gt;&amp; board) {<br \/>\n         backtracking(board);<br \/>\n    }<br \/>\n}; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>93. \u590d\u539f IP \u5730\u5740<br \/>\n\u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09;<br \/>\n\u9898\u76ee\u8981\u6c42&#xff1a; \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32 s&#xff0c;\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u5408\u6cd5 IP \u5730\u5740\u3002 \u4ec0\u4e48\u662f\u201c\u5408\u6cd5 IP\u201d&#xff1f;<br \/>\n\u4e00\u4e2a IP \u5730\u5740\u5fc5\u987b\u6ee1\u8db3&#xff1a; \u7531 4 \u6bb5\u7ec4\u6210&#xff0c;\u7528 . \u5206\u9694  \u6bcf\u4e00\u6bb5&#xff1a; \u6570\u503c\u5728 0 ~ 255  \u4e0d\u80fd\u6709\u524d\u5bfc 0&#xff08;\u9664\u975e\u5c31\u662f \\&#8221;0\\&#8221;&#xff09;<br \/>\n\u4f8b\u5982&#xff1a; \\&#8221;2552551113<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,427,925],"topic":[],"class_list":["post-74396","post","type-post","status-publish","format-standard","hentry","category-server","tag-leetcode","tag-427","tag-925"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/74396.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"93. \u590d\u539f IP \u5730\u5740 \u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09; \u9898\u76ee\u8981\u6c42&#xff1a; \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32 s&#xff0c;\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u5408\u6cd5 IP \u5730\u5740\u3002 \u4ec0\u4e48\u662f\u201c\u5408\u6cd5 IP\u201d&#xff1f; \u4e00\u4e2a IP \u5730\u5740\u5fc5\u987b\u6ee1\u8db3&#xff1a; \u7531 4 \u6bb5\u7ec4\u6210&#xff0c;\u7528 . \u5206\u9694 \u6bcf\u4e00\u6bb5&#xff1a; \u6570\u503c\u5728 0 ~ 255 \u4e0d\u80fd\u6709\u524d\u5bfc 0&#xff08;\u9664\u975e\u5c31\u662f &quot;0&quot;&#xff09;  \u4f8b\u5982&#xff1a; &quot;2552551113\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/74396.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-09T10:49:32+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74396.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/74396.html\",\"name\":\"Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-09T10:49:32+00:00\",\"dateModified\":\"2026-02-09T10:49:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/74396.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/74396.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74396.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Leetcode\u56de\u6eaf\u7b97\u6cd5part2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/74396.html","og_locale":"zh_CN","og_type":"article","og_title":"Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"93. \u590d\u539f IP \u5730\u5740 \u6574\u4f53\u601d\u8def&#xff08;\u5148\u4e0d\u770b\u4ee3\u7801&#xff09; \u9898\u76ee\u8981\u6c42&#xff1a; \u7ed9\u5b9a\u4e00\u4e2a\u53ea\u5305\u542b\u6570\u5b57\u7684\u5b57\u7b26\u4e32 s&#xff0c;\u8fd4\u56de\u6240\u6709\u53ef\u80fd\u7684\u5408\u6cd5 IP \u5730\u5740\u3002 \u4ec0\u4e48\u662f\u201c\u5408\u6cd5 IP\u201d&#xff1f; \u4e00\u4e2a IP \u5730\u5740\u5fc5\u987b\u6ee1\u8db3&#xff1a; \u7531 4 \u6bb5\u7ec4\u6210&#xff0c;\u7528 . \u5206\u9694 \u6bcf\u4e00\u6bb5&#xff1a; \u6570\u503c\u5728 0 ~ 255 \u4e0d\u80fd\u6709\u524d\u5bfc 0&#xff08;\u9664\u975e\u5c31\u662f \"0\"&#xff09;  \u4f8b\u5982&#xff1a; \"2552551113","og_url":"https:\/\/www.wsisp.com\/helps\/74396.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-09T10:49:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/74396.html","url":"https:\/\/www.wsisp.com\/helps\/74396.html","name":"Leetcode\u56de\u6eaf\u7b97\u6cd5part2 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-09T10:49:32+00:00","dateModified":"2026-02-09T10:49:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/74396.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/74396.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/74396.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Leetcode\u56de\u6eaf\u7b97\u6cd5part2"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=74396"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74396\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=74396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=74396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=74396"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=74396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}