{"id":414,"date":"2020-04-30T12:40:52","date_gmt":"2020-04-30T04:40:52","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=414"},"modified":"2020-04-30T12:42:57","modified_gmt":"2020-04-30T04:42:57","slug":"leetcode%e5%88%b7%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/04\/30\/leetcode%e5%88%b7%e9%a2%98\/","title":{"rendered":"leetcode\u5237\u9898"},"content":{"rendered":"<p><a href=\"https:\/\/leetcode-cn.com\/problems\/happy-number\/\">leetcode (59)\u5feb\u4e50\u6570<\/a><br \/>\n\u300c\u5feb\u4e50\u6570\u300d\u5b9a\u4e49\u4e3a\uff1a\u5bf9\u4e8e\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u6bcf\u4e00\u6b21\u5c06\u8be5\u6570\u66ff\u6362\u4e3a\u5b83\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u7684\u6570\u5b57\u7684\u5e73\u65b9\u548c\uff0c\u7136\u540e\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\u76f4\u5230\u8fd9\u4e2a\u6570\u53d8\u4e3a 1\uff0c\u4e5f\u53ef\u80fd\u662f \u65e0\u9650\u5faa\u73af \u4f46\u59cb\u7ec8\u53d8\u4e0d\u5230 1\u3002\u5982\u679c \u53ef\u4ee5\u53d8\u4e3a\u00a0 1\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6570\u5c31\u662f\u5feb\u4e50\u6570\u3002<\/p>\n<p>\u53d1\u73b0\u53ea\u6709\u4e00\u4e2a\u5faa\u73af\uff1a 4\u219216\u219237\u219258\u219289\u2192145\u219242\u219220\u21924\u3002\u6240\u6709\u5176\u4ed6\u6570\u5b57\u90fd\u5728\u8fdb\u5165\u8fd9\u4e2a\u5faa\u73af\u7684\u94fe\u4e0a\uff0c\u6216\u8005\u5728\u8fdb\u5165 1 \u7684\u94fe\u4e0a\u3002<\/p>\n<pre><code class=\"language-c++\">class Solution {\npublic:\n    int next(int n){\n        int ans = 0;\n        while (n){\n            ans += (n%10)*(n%10);\n            n \/= 10;\n        }\n        return ans;\n    }\n    bool isHappy(int n) {\n        int tmp = n;\n        while (tmp!=1 &amp;&amp; tmp!=4){\n            tmp = next(tmp);\n        }\n        return tmp==1?1:0;\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>leetcode (59)\u5feb\u4e50\u6570 \u300c\u5feb\u4e50\u6570\u300d\u5b9a\u4e49\u4e3a\uff1a\u5bf9\u4e8e\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u6bcf\u4e00\u6b21\u5c06\u8be5\u6570\u66ff\u6362\u4e3a\u5b83\u6bcf\u4e2a\u4f4d\u7f6e\u4e0a\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[39],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/414"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=414"}],"version-history":[{"count":2,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":416,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions\/416"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}