{"id":113254,"date":"2026-10-05T20:09:02","date_gmt":"2026-10-05T12:09:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/113254.html"},"modified":"2026-10-05T20:09:02","modified_gmt":"2026-10-05T12:09:02","slug":"day20-leetcode-202-%e5%bf%ab%e4%b9%90%e6%95%b0%ef%bc%9a%e4%bb%8e-set-%e5%88%a4%e9%87%8d%e5%88%b0-%e5%bf%ab%e6%85%a2%e6%8c%87%e9%92%88","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/113254.html","title":{"rendered":"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488"},"content":{"rendered":"<\/p>\n<h4>LeetCode 202 \u5feb\u4e50\u6570&#xff1a;\u4ece Set \u5224\u91cd\u5230 Floyd \u5feb\u6162\u6307\u9488<\/h4>\n<ul>\n<li>LeetCode 202 \u5feb\u4e50\u6570<\/li>\n<li>\u4e00\u3001\u600e\u4e48\u628a\u6570\u5b57\u4e00\u4f4d\u4e00\u4f4d\u62c6\u51fa\u6765&#xff1f;<\/li>\n<li>\u4e8c\u3001\u666e\u901a\u7248\u672c&#xff1a;\u5b57\u5178\u67e5\u5e73\u65b9 &#043; Set \u5224\u91cd<\/li>\n<li>\u4e09\u3001\u4f18\u5316\u4e00&#xff1a;\u5e73\u65b9\u6ca1\u5fc5\u8981\u4f7f\u7528\u5b57\u5178\u4fdd\u5b58<\/li>\n<li>\u56db\u3001\u8fd8\u80fd\u7ee7\u7eed\u4f18\u5316\u5417&#xff1f;<\/li>\n<li>\u4e94\u3001\u4f18\u5316\u4e8c&#xff1a;Floyd \u5feb\u6162\u6307\u9488\u5224\u73af<\/li>\n<li>\n<ul>\n<li>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u4ee5\u5224\u65ad&#xff1f;<\/li>\n<li>\n<ul>\n<li>\u60c5\u51b5\u4e00&#xff1a;fast \u5230\u8fbe 1<\/li>\n<li>\u60c5\u51b5\u4e8c&#xff1a;slow \u548c fast \u76f8\u9047<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u516d\u3001\u4ece Set \u662f\u600e\u4e48\u60f3\u5230\u5feb\u6162\u6307\u9488\u7684&#xff1f;<\/li>\n<li>\u4e03\u3001\u4e09\u4e2a\u7248\u672c\u7684\u533a\u522b<\/li>\n<\/ul>\n<h2>LeetCode 202 \u5feb\u4e50\u6570<\/h2>\n<p>LeetCode 202 \u5feb\u4e50\u6570<\/p>\n<p>\u8fd9\u9053\u9898\u4f1a\u4e0d\u65ad\u8fdb\u884c\u540c\u4e00\u4e2a\u64cd\u4f5c&#xff1a;<\/p>\n<p>\u628a\u5f53\u524d\u6570\u5b57\u7684\u6bcf\u4e00\u4f4d\u53d6\u51fa\u6765&#xff0c;\u5206\u522b\u5e73\u65b9\u4ee5\u540e\u76f8\u52a0&#xff0c;\u5f97\u5230\u65b0\u7684\u6570\u5b57&#xff0c;\u7136\u540e\u7ee7\u7eed\u91cd\u590d\u3002<\/p>\n<p>\u4f8b\u5982, n &#061; 19&#xff1a;<\/p>\n<p>19 \u2192 1\u00b2 &#043; 9\u00b2 \u2192 82<\/p>\n<p>82 \u2192 8\u00b2 &#043; 2\u00b2 \u2192 68<\/p>\n<p>68 \u2192 6\u00b2 &#043; 8\u00b2 \u2192 100<\/p>\n<p>100 \u2192 1\u00b2 \u2192 1<\/p>\n<p>\u6700\u7ec8\u80fd\u591f\u5f97\u5230 1&#xff0c;\u6240\u4ee5 19 \u662f\u5feb\u4e50\u6570\u3002<\/p>\n<p>\u6574\u4e2a\u6d41\u7a0b\u770b\u4e0b\u6765, \u53ef\u4ee5\u60f3\u5230\u8fd9\u9053\u9898\u771f\u6b63\u9700\u8981\u89e3\u51b3\u4e24\u4e2a\u95ee\u9898&#xff1a;<\/p>\n<li>\u600e\u4e48\u628a\u4e00\u4e2a\u4e0d\u77e5\u9053\u6709\u591a\u5c11\u4f4d\u7684\u6570\u5b57\u9010\u4f4d\u62c6\u5f00&#xff1f;<\/li>\n<li>\u5982\u679c\u4e00\u76f4\u5f97\u4e0d\u5230 1&#xff0c;\u4ec0\u4e48\u65f6\u5019\u53ef\u4ee5\u786e\u5b9a\u5b83\u6c38\u8fdc\u4e0d\u4f1a\u5f97\u5230 1&#xff1f;<\/li>\n<hr \/>\n<h2>\u4e00\u3001\u600e\u4e48\u628a\u6570\u5b57\u4e00\u4f4d\u4e00\u4f4d\u62c6\u51fa\u6765&#xff1f;<\/h2>\n<p>\u6bd4\u5982&#xff1a;<\/p>\n<p>n &#061; 1234<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7&#xff1a;<\/p>\n<p>digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>\u53d6\u5f97\u6700\u540e\u4e00\u4f4d&#xff1a;<\/p>\n<p>4<\/p>\n<p>\u7136\u540e&#xff1a;<\/p>\n<p>n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>\u5220\u9664\u6700\u540e\u4e00\u4f4d&#xff1a;<\/p>\n<p>1234 \u2192 123<\/p>\n<p>\u7ee7\u7eed&#xff1a;<\/p>\n<p>123 \u2192 3<br \/>\n12  \u2192 2<br \/>\n1   \u2192 1<br \/>\n0   \u2192 \u505c\u6b62<\/p>\n<p>\u6240\u4ee5\u4e0d\u9700\u8981\u63d0\u524d\u77e5\u9053 n \u662f\u51e0\u4f4d\u6570&#xff0c;\u53ea\u9700\u8981&#xff1a;<\/p>\n<p><span class=\"token keyword\">while<\/span> n <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><br \/>\n    total <span class=\"token operator\">&#043;&#061;<\/span> digit <span class=\"token operator\">*<\/span> digit<br \/>\n    n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>\u5c31\u53ef\u4ee5\u628a\u6240\u6709\u4f4d\u90fd\u5904\u7406\u5b8c\u3002<\/p>\n<hr \/>\n<h2>\u4e8c\u3001\u666e\u901a\u7248\u672c&#xff1a;\u5b57\u5178\u67e5\u5e73\u65b9 &#043; Set \u5224\u91cd<\/h2>\n<p>\u6211\u6700\u5f00\u59cb\u60f3\u5230&#xff0c;\u53ef\u4ee5\u63d0\u524d\u628a 0 ~ 9 \u7684\u5e73\u65b9\u4fdd\u5b58\u5230\u5b57\u5178\u91cc&#xff1a;<\/p>\n<p>(\u56e0\u4e3a\u4e00\u4f4d\u6570\u5c31\u662f\u5728\u8fd9\u4e2a\u8303\u56f4\u91cc\u9762)<\/p>\n<p>nums <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    nums<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> i <span class=\"token operator\">**<\/span> <span class=\"token number\">2<\/span><\/p>\n<p>\u540e\u9762\u5f97\u5230\u67d0\u4e00\u4f4d digit \u65f6&#xff0c;\u76f4\u63a5\u67e5\u8be2\u4f7f\u7528&#xff1a;<\/p>\n<p>nums<span class=\"token punctuation\">[<\/span>digit<span class=\"token punctuation\">]<\/span><\/p>\n<p>\u53d6\u51fa\u5bf9\u5e94\u7684\u5e73\u65b9\u3002<\/p>\n<p>&#x1f6a9; \u53e6\u4e00\u4e2a\u95ee\u9898\u662f&#xff1a;\u4ec0\u4e48\u65f6\u5019\u505c\u6b62&#xff1f;<\/p>\n<p>\u4f8b\u5982\u975e\u5feb\u4e50\u6570\u53ef\u80fd\u4f1a\u51fa\u73b0&#xff1a;<\/p>\n<p>2<br \/>\n\u2192 4<br \/>\n\u2192 16<br \/>\n\u2192 37<br \/>\n\u2192 58<br \/>\n\u2192 89<br \/>\n\u2192 145<br \/>\n\u2192 42<br \/>\n\u2192 20<br \/>\n\u2192 4 \u2190 \u7b2c\u4e8c\u6b21\u51fa\u73b0\u4e86<br \/>\n\u2192 16<br \/>\n\u2192 &#8230;<\/p>\n<p>\u8fd9\u91cc 4 \u7b2c\u4e8c\u6b21\u51fa\u73b0\u4ee5\u540e&#xff0c;\u540e\u9762\u7684\u8fc7\u7a0b\u5c31\u4f1a\u548c\u4e4b\u524d\u5b8c\u5168\u4e00\u6837&#xff0c;\u56e0\u6b64\u5df2\u7ecf\u8fdb\u5165\u4e86\u4e00\u4e2a\u5faa\u73af&#xff0c;\u4e0d\u53ef\u80fd\u518d\u7a81\u7136\u5f97\u5230 1\u3002<\/p>\n<p>\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a set \u7528\u4e8e\u4fdd\u5b58\u4e4b\u524d\u51fa\u73b0\u8fc7\u7684\u6570\u5b57&#xff1a;<\/p>\n<p>seen <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5982\u679c&#xff1a;<\/p>\n<p>n <span class=\"token keyword\">in<\/span> seen<\/p>\n<p>\u8bf4\u660e\u5f53\u524d\u6570\u5b57\u5df2\u7ecf\u51fa\u73b0\u8fc7\u4e00\u6b21&#xff0c;\u4e5f\u5c31\u662f\u8fdb\u5165\u4e86\u5faa\u73af&#xff0c;\u53ef\u4ee5\u76f4\u63a5&#xff1a;<\/p>\n<p><span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>\u2728 \u5b8c\u6574\u4ee3\u7801&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">isHappy<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        nums <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>        <span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            nums<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> i <span class=\"token operator\">**<\/span> <span class=\"token number\">2<\/span><\/p>\n<p>        seen <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> n <span class=\"token keyword\">in<\/span> seen<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>            seen<span class=\"token punctuation\">.<\/span>add<span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><\/p>\n<p>            total <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>            <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><br \/>\n                total <span class=\"token operator\">&#043;&#061;<\/span> nums<span class=\"token punctuation\">[<\/span>digit<span class=\"token punctuation\">]<\/span><br \/>\n                n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>            n <span class=\"token operator\">&#061;<\/span> total<\/p>\n<p>        <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><\/p>\n<hr \/>\n<h2>\u4e09\u3001\u4f18\u5316\u4e00&#xff1a;\u5e73\u65b9\u6ca1\u5fc5\u8981\u4f7f\u7528\u5b57\u5178\u4fdd\u5b58<\/h2>\n<p>\u867d\u7136\u5b57\u5178\u67e5\u8868\u53ef\u4ee5\u505a&#xff0c;\u4f46\u8fd9\u91cc\u5b9e\u9645\u4e0a\u53ea\u6709 0 ~ 9 \u5341\u4e2a\u6570\u5b57&#xff0c;\u800c\u4e14\u8ba1\u7b97&#xff1a;<\/p>\n<p>digit <span class=\"token operator\">*<\/span> digit<\/p>\n<p>\u672c\u8eab\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p>\u4f7f\u7528\u5b57\u5178\u8fd8\u9700\u8981\u5148\u521b\u5efa\u5b57\u5178&#xff0c;\u518d\u8fdb\u884c\u54c8\u5e0c\u67e5\u627e&#xff0c;\u6240\u4ee5\u8fd9\u91cc\u76f4\u63a5\u8ba1\u7b97\u53cd\u800c\u66f4\u52a0\u81ea\u7136\u3002<\/p>\n<p>\u4e8e\u662f&#xff1a;<\/p>\n<p>total <span class=\"token operator\">&#043;&#061;<\/span> nums<span class=\"token punctuation\">[<\/span>digit<span class=\"token punctuation\">]<\/span><\/p>\n<p>\u53ef\u4ee5\u76f4\u63a5\u6539\u6210&#xff1a;<\/p>\n<p>total <span class=\"token operator\">&#043;&#061;<\/span> digit <span class=\"token operator\">*<\/span> digit<\/p>\n<p>\u4ee3\u7801\u5c31\u7b80\u5316\u6210&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">isHappy<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        seen <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> n <span class=\"token keyword\">in<\/span> seen<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">False<\/span><\/p>\n<p>            seen<span class=\"token punctuation\">.<\/span>add<span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><\/p>\n<p>            total <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>            <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><br \/>\n                total <span class=\"token operator\">&#043;&#061;<\/span> digit <span class=\"token operator\">*<\/span> digit<br \/>\n                n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>            n <span class=\"token operator\">&#061;<\/span> total<\/p>\n<p>        <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">True<\/span><\/p>\n<p>\u8fd9\u91cc\u4e5f\u53ef\u4ee5\u4fdd\u7559 1\u300110\u3001100 \u4f5c\u4e3a\u63d0\u524d\u6210\u529f\u7684\u6761\u4ef6\u3002<\/p>\n<p>\u56e0\u4e3a&#xff1a;<\/p>\n<p>10  \u2192 1\u00b2 &#043; 0\u00b2      \u2192 1<br \/>\n100 \u2192 1\u00b2 &#043; 0\u00b2 &#043; 0\u00b2 \u2192 1<\/p>\n<p>\u6240\u4ee5\u5f53\u67d0\u4e00\u8f6e\u5df2\u7ecf\u5f97\u5230 10 \u6216 100 \u65f6&#xff0c;\u5176\u5b9e\u5df2\u7ecf\u53ef\u4ee5\u786e\u5b9a\u6700\u540e\u4e00\u5b9a\u4f1a\u5230 1&#xff0c;\u6ca1\u5fc5\u8981\u518d\u591a\u8fdb\u884c\u4e00\u6b21\u62c6\u4f4d\u548c\u5e73\u65b9\u6c42\u548c\u3002<\/p>\n<p>\u56e0\u6b64\u53ef\u4ee5\u5199\u6210&#xff1a;<\/p>\n<p><span class=\"token keyword\">while<\/span> n <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">100<\/span> <span class=\"token keyword\">and<\/span> n <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">10<\/span> <span class=\"token keyword\">and<\/span> n <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">:<\/span><\/p>\n<p>\u8fd9\u6837\u4f8b\u5982&#xff1a;<\/p>\n<p>19<br \/>\n\u2192 82<br \/>\n\u2192 68<br \/>\n\u2192 100<br \/>\n\u2192 \u76f4\u63a5\u8fd4\u56de True<\/p>\n<p>\u800c\u4e0d\u662f\u518d\u7ee7\u7eed\u8ba1\u7b97&#xff1a;<\/p>\n<p>100<br \/>\n\u2192 1<br \/>\n\u2192 True<\/p>\n<p>\u4e0d\u8fc7\u8fd9\u53ea\u662f\u4e00\u4e2a\u5f88\u5c0f\u7684\u63d0\u524d\u9000\u51fa\u4f18\u5316&#xff0c;\u4e3b\u8981\u51cf\u5c11\u7684\u662f\u4e00\u8f6e\u989d\u5916\u8ba1\u7b97&#xff0c;\u5e76\u4e0d\u4f1a\u6539\u53d8\u6574\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u3002<\/p>\n<hr \/>\n<h2>\u56db\u3001\u8fd8\u80fd\u7ee7\u7eed\u4f18\u5316\u5417&#xff1f;<\/h2>\n<p>\u73b0\u5728\u5269\u4e0b\u7684\u989d\u5916\u7a7a\u95f4\u4e3b\u8981\u6765\u81ea&#xff1a;<\/p>\n<p>seen <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4f46\u91cd\u65b0\u89c2\u5bdf seen \u7684\u4f5c\u7528&#xff0c;\u4f1a\u53d1\u73b0\u6211\u4eec\u5176\u5b9e\u5e76\u4e0d\u5173\u5fc3&#xff1a;<\/p>\n<p>\u4e4b\u524d\u5230\u5e95\u51fa\u73b0\u8fc7\u54ea\u4e9b\u6570\u5b57\u3002<\/p>\n<p>\u771f\u6b63\u5173\u5fc3\u7684\u53ea\u662f&#xff1a;<\/p>\n<p>\u5f53\u524d\u6570\u5b57\u6709\u6ca1\u6709\u8fdb\u5165\u5faa\u73af&#xff1f;<\/p>\n<p>\u8fd9\u5c31\u548c\u4e4b\u524d\u505a\u8fc7\u7684\u73af\u5f62\u94fe\u8868\u5224\u73af\u975e\u5e38\u50cf\u3002\u4e5f\u5c31\u662f [ 141 ] \u8fd9\u9053\u9898<\/p>\n<p>\u628a\u6bcf\u4e00\u6b21\u201c\u5404\u4f4d\u5e73\u65b9\u548c\u201d\u770b\u6210\u4ece\u4e00\u4e2a\u72b6\u6001\u8d70\u5411\u4e0b\u4e00\u4e2a\u72b6\u6001&#xff1a;<\/p>\n<p>n<br \/>\n\u2192 next(n)<br \/>\n\u2192 next(next(n))<br \/>\n\u2192 &#8230;<\/p>\n<p>\u5feb\u4e50\u6570&#xff1a;<\/p>\n<p>19 \u2192 82 \u2192 68 \u2192 100 \u2192 1<\/p>\n<p>\u975e\u5feb\u4e50\u6570&#xff1a;<\/p>\n<p>2 \u2192 4 \u2192 16 \u2192 37 \u2192 &#8230; \u2192 20 \u2192 4 \u2192 16 \u2192 &#8230;<br \/>\n                                    \u2191         \u2193<br \/>\n                                    \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<p>\u8fd9\u6837\u770b\u4ee5\u540e&#xff0c;\u95ee\u9898\u5df2\u7ecf\u53d8\u6210&#xff1a;<\/p>\n<p>\u8fd9\u6761\u4e0d\u65ad\u5411\u540e\u7684\u8def\u5f84&#xff0c;\u6700\u7ec8\u662f\u5230\u8fbe 1&#xff0c;\u8fd8\u662f\u8fdb\u5165\u4e00\u4e2a\u73af&#xff1f;<\/p>\n<p>\u65e2\u7136\u662f\u5728\u5224\u65ad\u6709\u6ca1\u6709\u73af&#xff0c;\u5c31\u53ef\u4ee5\u8054\u60f3\u5230\u4e4b\u524d\u73af\u5f62\u94fe\u8868\u4f7f\u7528\u8fc7\u7684&#xff1a;<\/p>\n<p>\u5feb\u6162\u6307\u9488 \/ Floyd \u5224\u73af\u3002<\/p>\n<hr \/>\n<h2>\u4e94\u3001\u4f18\u5316\u4e8c&#xff1a;Floyd \u5feb\u6162\u6307\u9488\u5224\u73af<\/h2>\n<p>\u9996\u5148\u628a\u201c\u4e00\u6b21\u8f6c\u6362\u201d\u5355\u72ec\u5199\u6210\u4e00\u4e2a\u51fd\u6570&#xff1a;<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">get_next<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    total <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>    <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><br \/>\n        total <span class=\"token operator\">&#043;&#061;<\/span> digit <span class=\"token operator\">*<\/span> digit<br \/>\n        n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> total<\/p>\n<p>\u5b83\u8d1f\u8d23&#xff1a;<\/p>\n<p>19 \u2192 82<br \/>\n82 \u2192 68<br \/>\n68 \u2192 100<br \/>\n100 \u2192 1<\/p>\n<p>\u4e5f\u5c31\u662f\u7ed9\u4e00\u4e2a\u5f53\u524d\u6570\u5b57&#xff0c;\u8fd4\u56de\u5b83\u7684\u4e0b\u4e00\u4e2a\u6570\u5b57\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u8bbe\u7f6e\u4e24\u4e2a\u6307\u9488&#xff1a;<\/p>\n<p>slow <span class=\"token operator\">&#061;<\/span> n<br \/>\nfast <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5176\u4e2d&#xff1a;<\/p>\n<p>slow \u2192 \u6bcf\u6b21\u8fdb\u884c\u4e00\u6b21\u8f6c\u6362<\/p>\n<p>fast \u2192 \u6bcf\u6b21\u8fdb\u884c\u4e24\u6b21\u8f6c\u6362<\/p>\n<p>\u4e5f\u5c31\u662f&#xff1a;<\/p>\n<p>slow <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>slow<span class=\"token punctuation\">)<\/span><\/p>\n<p>fast <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>get_next<span class=\"token punctuation\">(<\/span>fast<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u548c\u73af\u5f62\u94fe\u8868\u5b8c\u5168\u5bf9\u5e94&#xff1a;<\/p>\n<p>slow &#061; slow.next<br \/>\nfast &#061; fast.next.next<\/p>\n<p>\u5728\u5feb\u4e50\u6570\u4e2d\u5219\u53d8\u6210&#xff1a;<\/p>\n<p>slow &#061; next(slow)<br \/>\nfast &#061; next(next(fast))<\/p>\n<p>\u53ea\u662f\u539f\u6765\u7684\u201c\u8d70\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\u201d&#xff0c;\u73b0\u5728\u53d8\u6210\u4e86\u201c\u8ba1\u7b97\u4e0b\u4e00\u6b21\u6570\u503c\u201d\u3002<\/p>\n<hr \/>\n<h3>\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u4ee5\u5224\u65ad&#xff1f;<\/h3>\n<p>\u6700\u7ec8\u53ea\u6709\u4e24\u79cd\u60c5\u51b5\u3002<\/p>\n<h4>\u60c5\u51b5\u4e00&#xff1a;fast \u5230\u8fbe 1<\/h4>\n<p>\u4f8b\u5982&#xff1a;<\/p>\n<p>19 \u2192 82 \u2192 68 \u2192 100 \u2192 1<\/p>\n<p>\u5982\u679c&#xff1a;<\/p>\n<p>fast <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><\/p>\n<p>\u8bf4\u660e\u8fd9\u6761\u8def\u5f84\u6700\u7ec8\u80fd\u591f\u8d70\u5230 1&#xff0c;\u56e0\u6b64\u662f\u5feb\u4e50\u6570\u3002<\/p>\n<h4>\u60c5\u51b5\u4e8c&#xff1a;slow \u548c fast \u76f8\u9047<\/h4>\n<p>\u5982\u679c\u8fd9\u6761\u8def\u5f84\u8fdb\u5165\u5faa\u73af&#xff0c;\u90a3\u4e48\u548c\u73af\u5f62\u94fe\u8868\u4e00\u6837&#xff1a;<\/p>\n<p>slow \u6bcf\u6b21\u8d70\u4e00\u6b65<br \/>\nfast \u6bcf\u6b21\u8d70\u4e24\u6b65<\/p>\n<p>\u4e24\u8005\u6700\u7ec8\u4e00\u5b9a\u4f1a\u5728\u73af\u4e2d\u76f8\u9047\u3002<\/p>\n<p>\u6240\u4ee5&#xff1a;<\/p>\n<p>slow <span class=\"token operator\">&#061;&#061;<\/span> fast<\/p>\n<p>\u800c\u6b64\u65f6\u53c8\u6ca1\u6709\u5230 1&#xff0c;\u5c31\u8bf4\u660e\u8fdb\u5165\u4e86\u975e\u5feb\u4e50\u6570\u7684\u5faa\u73af\u3002<\/p>\n<p>\u56e0\u6b64\u5faa\u73af\u6761\u4ef6\u53ef\u4ee5\u5199\u6210&#xff1a;<\/p>\n<p><span class=\"token keyword\">while<\/span> fast <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token keyword\">and<\/span> slow <span class=\"token operator\">!&#061;<\/span> fast<span class=\"token punctuation\">:<\/span><\/p>\n<p>\u53ea\u8981&#xff1a;<\/p>\n<p>\u8fd8\u6ca1\u5230 1<br \/>\n\u5e76\u4e14<br \/>\n\u5feb\u6162\u6307\u9488\u8fd8\u6ca1\u76f8\u9047<\/p>\n<p>\u5c31\u7ee7\u7eed\u8d70\u3002<\/p>\n<p>&#x1f6a9; \u5b8c\u6574\u4ee3\u7801&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">isHappy<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">def<\/span> <span class=\"token function\">get_next<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            total <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>            <span class=\"token keyword\">while<\/span> n <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                digit <span class=\"token operator\">&#061;<\/span> n <span class=\"token operator\">%<\/span> <span class=\"token number\">10<\/span><br \/>\n                total <span class=\"token operator\">&#043;&#061;<\/span> digit <span class=\"token operator\">*<\/span> digit<br \/>\n                n <span class=\"token operator\">\/\/&#061;<\/span> <span class=\"token number\">10<\/span><\/p>\n<p>            <span class=\"token keyword\">return<\/span> total<\/p>\n<p>        slow <span class=\"token operator\">&#061;<\/span> n<br \/>\n        fast <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">while<\/span> fast <span class=\"token operator\">!&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token keyword\">and<\/span> slow <span class=\"token operator\">!&#061;<\/span> fast<span class=\"token punctuation\">:<\/span><br \/>\n            slow <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>slow<span class=\"token punctuation\">)<\/span><br \/>\n            fast <span class=\"token operator\">&#061;<\/span> get_next<span class=\"token punctuation\">(<\/span>get_next<span class=\"token punctuation\">(<\/span>fast<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>        <span class=\"token keyword\">return<\/span> fast <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><\/p>\n<hr \/>\n<h2>\u516d\u3001\u4ece Set \u662f\u600e\u4e48\u60f3\u5230\u5feb\u6162\u6307\u9488\u7684&#xff1f;<\/h2>\n<p>\u6700\u5f00\u59cb\u4f7f\u7528 set&#xff1a;<\/p>\n<p>\u4e0d\u65ad\u8ba1\u7b97\u65b0\u7684 n<br \/>\n\u2193<br \/>\n\u6bcf\u51fa\u73b0\u4e00\u4e2a n \u5c31\u4fdd\u5b58\u5230 seen<br \/>\n\u2193<br \/>\n\u5982\u679c\u4ee5\u540e\u518d\u6b21\u51fa\u73b0<br \/>\n\u2193<br \/>\n\u8bf4\u660e\u8fdb\u5165\u5faa\u73af<\/p>\n<p>\u7136\u540e\u7ee7\u7eed\u60f3&#xff1a;<\/p>\n<p>\u6211\u4fdd\u5b58\u8fd9\u4e9b\u6570\u5b57&#xff0c;\u771f\u6b63\u7684\u76ee\u7684\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u4e0d\u662f\u4e3a\u4e86\u4ee5\u540e\u4f7f\u7528\u5b83\u4eec\u7684\u503c&#xff0c;\u800c\u53ea\u662f\u4e3a\u4e86\u5224\u65ad&#xff1a;<\/p>\n<p>\u6709\u6ca1\u6709\u51fa\u73b0\u5faa\u73af&#xff1f;<\/p>\n<p>\u65e2\u7136\u53ea\u662f\u5224\u73af&#xff0c;\u5c31\u4e0d\u4e00\u5b9a\u9700\u8981\u4fdd\u5b58\u6240\u6709\u5386\u53f2\u72b6\u6001\u3002<\/p>\n<p>\u4e8e\u662f\u53ef\u4ee5\u628a&#xff1a;<\/p>\n<p>n \u2192 \u4e0b\u4e00\u4e2a n \u2192 \u4e0b\u4e00\u4e2a n \u2192 &#8230;<\/p>\n<p>\u770b\u6210\u4e00\u6761\u94fe\u3002<\/p>\n<p>\u7136\u540e\u8054\u60f3\u5230\u73af\u5f62\u94fe\u8868&#xff1a;<\/p>\n<p>\u666e\u901a\u94fe\u8868\u5224\u73af&#xff1a;<br \/>\nslow \u4e00\u6b65<br \/>\nfast \u4e24\u6b65<\/p>\n<p>\u5feb\u4e50\u6570\u5224\u73af&#xff1a;<br \/>\nslow \u505a\u4e00\u6b21\u8f6c\u6362<br \/>\nfast \u505a\u4e24\u6b21\u8f6c\u6362<\/p>\n<p>\u6240\u4ee5\u4f18\u5316\u8fc7\u7a0b\u5c31\u662f&#xff1a;<\/p>\n<p>Set \u8bb0\u5f55\u6240\u6709\u5386\u53f2\u72b6\u6001<br \/>\n\u2193<br \/>\n\u53d1\u73b0\u771f\u6b63\u9700\u8981\u7684\u53ea\u662f\u201c\u662f\u5426\u6210\u73af\u201d<br \/>\n\u2193<br \/>\n\u628a\u6bcf\u4e00\u4e2a\u6570\u5b57\u770b\u6210\u4e00\u4e2a\u8282\u70b9<br \/>\n\u2193<br \/>\n\u628a\u5e73\u65b9\u548c\u8f6c\u6362\u770b\u6210 next<br \/>\n\u2193<br \/>\n\u95ee\u9898\u53d8\u6210\u94fe\u8868\u5224\u73af<br \/>\n\u2193<br \/>\n\u4f7f\u7528 Floyd \u5feb\u6162\u6307\u9488<br \/>\n\u2193<br \/>\n\u4e0d\u518d\u9700\u8981 seen<\/p>\n<hr \/>\n<h2>\u4e03\u3001\u4e09\u4e2a\u7248\u672c\u7684\u533a\u522b<\/h2>\n<table>\n<tr>\u7248\u672c\u5224\u65ad\u5faa\u73af\u7684\u65b9\u6cd5\u989d\u5916\u7a7a\u95f4<\/tr>\n<tbody>\n<tr>\n<td>\u5b57\u5178 &#043; Set<\/td>\n<td>seen \u4fdd\u5b58\u5386\u53f2\u72b6\u6001&#xff0c;\u5b57\u5178\u4fdd\u5b58\u5e73\u65b9<\/td>\n<td align=\"right\">\u8f83\u591a<\/td>\n<\/tr>\n<tr>\n<td>\u76f4\u63a5\u5e73\u65b9 &#043; Set<\/td>\n<td>seen \u4fdd\u5b58\u5386\u53f2\u72b6\u6001<\/td>\n<td align=\"right\">O(\u5386\u53f2\u72b6\u6001\u6570)<\/td>\n<\/tr>\n<tr>\n<td>Floyd \u5feb\u6162\u6307\u9488<\/td>\n<td>\u5feb\u6162\u6307\u9488\u5224\u65ad\u662f\u5426\u6210\u73af<\/td>\n<td align=\"right\">O(1)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u4ee5\u8fd9\u9053\u9898\u6700\u540e\u53ef\u4ee5\u8bb0\u4f4f\u8fd9\u4e24\u4e2a\u6838\u5fc3\u77e5\u8bc6\u70b9&#xff1a;<\/p>\n<p>1. % 10 \u53d6\u6700\u540e\u4e00\u4f4d&#xff0c;\/\/ 10 \u5220\u9664\u6700\u540e\u4e00\u4f4d&#xff0c;\u53ef\u4ee5\u5904\u7406\u4e0d\u77e5\u9053\u4f4d\u6570\u7684\u6574\u6570\u3002<\/p>\n<p>2. \u5982\u679c\u4e00\u4e2a\u8fc7\u7a0b\u4f1a\u4e0d\u65ad\u4ece\u5f53\u524d\u72b6\u6001\u4ea7\u751f\u552f\u4e00\u7684\u4e0b\u4e00\u4e2a\u72b6\u6001&#xff0c;\u90a3\u4e48\u201c\u72b6\u6001\u91cd\u590d\u201d\u5176\u5b9e\u5c31\u662f\u6210\u73af&#xff0c;\u8fd9\u65f6\u5019\u9664\u4e86 Set \u5224\u91cd&#xff0c;\u8fd8\u53ef\u4ee5\u8fdb\u4e00\u6b65\u8003\u8651 Floyd \u5feb\u6162\u6307\u9488\u5224\u73af\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode 202 \u5feb\u4e50\u6570&#xff1a;\u4ece Set \u5224\u91cd\u5230 Floyd \u5feb\u6162\u6307\u9488LeetCode 202 \u5feb\u4e50\u6570\u4e00\u3001\u600e\u4e48\u628a\u6570\u5b57\u4e00\u4f4d\u4e00\u4f4d\u62c6\u51fa\u6765&#xff1f;\u4e8c\u3001\u666e\u901a\u7248\u672c&#xff1a;\u5b57\u5178\u67e5\u5e73\u65b9  Set \u5224\u91cd\u4e09\u3001\u4f18\u5316\u4e00&#xff1a;\u5e73\u65b9\u6ca1\u5fc5\u8981\u4f7f\u7528\u5b57\u5178\u4fdd\u5b58\u56db\u3001\u8fd8\u80fd\u7ee7\u7eed\u4f18\u5316\u5417&#xff1f;\u4e94\u3001\u4f18\u5316\u4e8c&#xff1a;Floyd \u5feb\u6162\u6307\u9488\u5224\u73af\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u4ee5\u5224\u65ad&#xff1f;\u60c5\u51b5\u4e00&#xff1a;fast \u5230\u8fbe 1\u60c5\u51b5\u4e8c&#xff1a;slow \u548c fast \u76f8\u9047\u516d\u3001\u4ece<\/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":[11653,2692,81,50,305,427],"topic":[],"class_list":["post-113254","post","type-post","status-publish","format-standard","hentry","category-server","tag-11653","tag-leetcode","tag-python","tag-50","tag-305","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \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\/113254.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"LeetCode 202 \u5feb\u4e50\u6570&#xff1a;\u4ece Set \u5224\u91cd\u5230 Floyd \u5feb\u6162\u6307\u9488LeetCode 202 \u5feb\u4e50\u6570\u4e00\u3001\u600e\u4e48\u628a\u6570\u5b57\u4e00\u4f4d\u4e00\u4f4d\u62c6\u51fa\u6765&#xff1f;\u4e8c\u3001\u666e\u901a\u7248\u672c&#xff1a;\u5b57\u5178\u67e5\u5e73\u65b9 Set \u5224\u91cd\u4e09\u3001\u4f18\u5316\u4e00&#xff1a;\u5e73\u65b9\u6ca1\u5fc5\u8981\u4f7f\u7528\u5b57\u5178\u4fdd\u5b58\u56db\u3001\u8fd8\u80fd\u7ee7\u7eed\u4f18\u5316\u5417&#xff1f;\u4e94\u3001\u4f18\u5316\u4e8c&#xff1a;Floyd \u5feb\u6162\u6307\u9488\u5224\u73af\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u4ee5\u5224\u65ad&#xff1f;\u60c5\u51b5\u4e00&#xff1a;fast \u5230\u8fbe 1\u60c5\u51b5\u4e8c&#xff1a;slow \u548c fast \u76f8\u9047\u516d\u3001\u4ece\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/113254.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T12:09:02+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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113254.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/113254.html\",\"name\":\"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-05T12:09:02+00:00\",\"dateModified\":\"2026-10-05T12:09:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/113254.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/113254.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/113254.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488\"}]},{\"@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":"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \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\/113254.html","og_locale":"zh_CN","og_type":"article","og_title":"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"LeetCode 202 \u5feb\u4e50\u6570&#xff1a;\u4ece Set \u5224\u91cd\u5230 Floyd \u5feb\u6162\u6307\u9488LeetCode 202 \u5feb\u4e50\u6570\u4e00\u3001\u600e\u4e48\u628a\u6570\u5b57\u4e00\u4f4d\u4e00\u4f4d\u62c6\u51fa\u6765&#xff1f;\u4e8c\u3001\u666e\u901a\u7248\u672c&#xff1a;\u5b57\u5178\u67e5\u5e73\u65b9 Set \u5224\u91cd\u4e09\u3001\u4f18\u5316\u4e00&#xff1a;\u5e73\u65b9\u6ca1\u5fc5\u8981\u4f7f\u7528\u5b57\u5178\u4fdd\u5b58\u56db\u3001\u8fd8\u80fd\u7ee7\u7eed\u4f18\u5316\u5417&#xff1f;\u4e94\u3001\u4f18\u5316\u4e8c&#xff1a;Floyd \u5feb\u6162\u6307\u9488\u5224\u73af\u4e3a\u4ec0\u4e48\u8fd9\u6837\u53ef\u4ee5\u5224\u65ad&#xff1f;\u60c5\u51b5\u4e00&#xff1a;fast \u5230\u8fbe 1\u60c5\u51b5\u4e8c&#xff1a;slow \u548c fast \u76f8\u9047\u516d\u3001\u4ece","og_url":"https:\/\/www.wsisp.com\/helps\/113254.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-05T12:09:02+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/113254.html","url":"https:\/\/www.wsisp.com\/helps\/113254.html","name":"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-05T12:09:02+00:00","dateModified":"2026-10-05T12:09:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/113254.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/113254.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/113254.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"DAY20: LeetCode 202 \u5feb\u4e50\u6570\uff1a\u4ece Set \u5224\u91cd\u5230 \u5feb\u6162\u6307\u9488"}]},{"@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\/113254","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=113254"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/113254\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=113254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=113254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=113254"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=113254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}