{"id":123,"date":"2017-08-12T20:20:07","date_gmt":"2017-08-12T12:20:07","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=123"},"modified":"2018-11-27T16:20:56","modified_gmt":"2018-11-27T08:20:56","slug":"70-climbing-stairs","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=123","title":{"rendered":"70. Climbing Stairs"},"content":{"rendered":"<p>You are climbing a stair case. It takes\u00a0<em>n<\/em>\u00a0steps to reach to the top.<\/p>\n<p>Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?<\/p>\n<p><strong>Note:<\/strong>\u00a0Given\u00a0<em>n<\/em>\u00a0will be a positive integer.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 2\r\n<strong>Output:<\/strong> 2\r\n<strong>Explanation:<\/strong> There are two ways to climb to the top.\r\n1. 1 step + 1 step\r\n2. 2 steps\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 3\r\n<strong>Output:<\/strong> 3\r\n<strong>Explanation:<\/strong> There are three ways to climb to the top.\r\n1. 1 step + 1 step + 1 step\r\n2. 1 step + 2 steps\r\n3. 2 steps + 1 step<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def __init__(self):\r\n        self.temp = {1: 1, 2: 2}\r\n\r\n    def climbStairs(self, n):\r\n        &quot;&quot;&quot;\r\n        :type n: int\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        if n in self.temp:\r\n            return self.temp[n]\r\n        else:\r\n            result = self.climbStairs(n-1)+self.climbStairs(n-2)\r\n            self.temp[n] = result\r\n        return result\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You are climbing a stair case. It takes\u00a0n\u00a0steps to reac<a href=\"https:\/\/www.ccagml.com\/?p=123\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">70. Climbing Stairs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/123"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=123"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}