Leetcode Golang 70. Climbing Stairs.go

2019-04-12 10:58:49 浏览数 (1)

版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412867

思路

dp的基础题目,走到当前一级台阶有两种方法,之前走一步,或者走两步

code

代码语言:javascript复制
func climbStairs(n int) int {
	if n < 2 {
		return 1
	}
	tmp := []int{1, 2}
	for i := 2; i < n; i   {
		tmp = append(tmp, tmp[i-1] tmp[i-2])
	}
	return tmp[n-1]
}

0 人点赞