1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // @Title: 爬楼梯 (Climbing Stairs)
// @Author: 15816537946@163.com
// @Date: 2020-12-04 10:49:53
// @Runtime: 0 ms
// @Memory: 1.9 MB
func climbStairs(n int) int {
if n <= 1 {
return 1
}
var j, ret int
for i := 0; i < n; i++ {
if i <= 1 {
j = 1
}
j, ret = ret, ret+j
}
return ret
}
|