go solution with dp


  • 0
    P
    func climbStairs(n int) int {
    	var dp = make([]int, n+2)
    	dp[0] = 1
    	dp[1] = 1
    	for i := 2; i <= n; i++ {
    		dp[i] = dp[i-1] + dp[i-2]
    	}
    	return dp[n]
    }
    
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.