70. 爬楼梯

2020-03-17  本文已影响0人  寂灭天骄小童鞋

https://leetcode-cn.com/problems/climbing-stairs/

func climbStairs(_ n: Int) -> Int {
    if n <= 1 {return 1}
    var first = 1
    var second = 2
    for _ in stride(from: 3, to: n + 1, by: 1) {
        let sum = first + second
        first = second
        second = sum
    }
    return second
}

上一篇 下一篇

猜你喜欢

热点阅读