Climbing stairs (go language)

Suppose you are climbing stairs. N order you need to get to the roof.

Every time you can climb one or two steps. How many different ways can climb to the roof of it?

Note: Given n is a positive integer.

Example 1:

Input: 2
Output: 2
explanation: There are two methods can climb the roof.
1.1 + 1-order-order
2.2 Order
Example 2:

Input: 3
Output: 3
Explanation: There are three methods can climb to the roof.
1.1 + 1 order + 1-order-order
2.1 + 2-order order
3.2 + 1-order-order

Source: stay button (LeetCode)
link: https: //leetcode-cn.com/problems/climbing-stairs
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.

 

 

 

FUNC climbStairs (n-int) int { 
    Switch n-{ 
    Case. 1: 
        return. 1 
    Case 2: 
        return 2 
    default: 
        DP1, DP2 is: =. 1, 2 
        for I: = 2; I <n-; I ++ { 
            DP1, DP2 is = DP2 is, DP1 DP2 + 
        } 
        return DP2 
    } 
} 

author: pppobear 
link: https: //leetcode-cn.com/problems/two-sum/solution/golangshi-xian-pa-lou-ti-by-pppobear/ 
source: stay button (LeetCode ) 
copyright reserved by the authors. Commercial reprint please contact the author authorized, non-commercial reprint please indicate the source.

  

Guess you like

Origin www.cnblogs.com/fangjianyi/p/11235841.html