{"id":997,"date":"2025-12-18T00:47:20","date_gmt":"2025-12-17T16:47:20","guid":{"rendered":"https:\/\/www.guanhaobo.cn\/?p=997"},"modified":"2025-12-18T00:47:20","modified_gmt":"2025-12-17T16:47:20","slug":"leetcode-70-%e7%88%ac%e6%a5%bc%e6%a2%af","status":"publish","type":"post","link":"https:\/\/www.guanhaobo.cn\/?p=997","title":{"rendered":"LeetCode 70 &#8211; \u722c\u697c\u68af"},"content":{"rendered":"<h1>\u9898\u76ee\u63cf\u8ff0<\/h1>\n<p>\u5047\u8bbe\u4f60\u6b63\u5728\u722c\u697c\u68af\u3002\u9700\u8981 n \u9636\u4f60\u624d\u80fd\u5230\u8fbe\u697c\u9876\u3002<br \/>\n\u6bcf\u6b21\u4f60\u53ef\u4ee5\u722c 1 \u6216 2 \u4e2a\u53f0\u9636\u3002\u4f60\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u65b9\u6cd5\u53ef\u4ee5\u722c\u5230\u697c\u9876\u5462\uff1f<\/p>\n<h1>\u9898\u76ee\u5206\u6790<\/h1>\n<p>f(n) = f(n &#8211; 1) + f(n &#8211; 2)<br \/>\n\u76f4\u63a5\u9012\u63a8\u5373\u53ef<\/p>\n<h1>Java<\/h1>\n<pre><code class=\"language-java line-numbers\">public int climbStairs(int n) {\n    int p1 = 1, p2 = 1;\n    int ans = 1;\n    for (int i = 2; i &lt;= n; i++) {\n        ans = p1 + p2;\n        p1 = p2;\n        p2 = ans;\n    }\n    return ans;\n}\n<\/code><\/pre>\n<h1>Kotlin<\/h1>\n<pre><code class=\"language-kotlin line-numbers\">fun climbStairs(n: Int): Int {\n    var p1 = 1\n    var p2 = 1\n    var ans = 1\n    for (i in 2..n) {\n        ans = p1 + p2\n        p1 = p2\n        p2 = ans\n    }\n    return ans\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u5047\u8bbe\u4f60\u6b63\u5728\u722c\u697c\u68af\u3002\u9700\u8981 n \u9636\u4f60\u624d\u80fd\u5230\u8fbe\u697c\u9876\u3002 \u6bcf\u6b21\u4f60\u53ef\u4ee5\u722c 1 \u6216 2 \u4e2a\u53f0\u9636\u3002\u4f60\u6709\u591a\u5c11\u79cd\u4e0d\u540c\u7684\u65b9 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[20,40],"class_list":["post-997","post","type-post","status-publish","format-standard","hentry","category-algo","tag-leetcode","tag-40"],"_links":{"self":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=997"}],"version-history":[{"count":1,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/997\/revisions"}],"predecessor-version":[{"id":998,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=\/wp\/v2\/posts\/997\/revisions\/998"}],"wp:attachment":[{"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guanhaobo.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}