u
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package top100liked
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// https://leetcode.cn/problems/climbing-stairs/?envType=study-plan-v2&envId=top-100-liked
|
||||
// 70. 爬楼梯
|
||||
//
|
||||
// 假设你正在爬楼梯。需要 `n` 阶你才能到达楼顶。
|
||||
// 每次你可以爬 `1` 或 `2` 个台阶。你有多少种不同的方法可以爬到楼顶呢?
|
||||
// 示例 1:
|
||||
// 输入:n = 2
|
||||
// 输出:2
|
||||
// 解释:有两种方法可以爬到楼顶。
|
||||
// 1. 1 阶 + 1 阶
|
||||
// 2. 2 阶
|
||||
// 示例 2:
|
||||
// 输入:n = 3
|
||||
// 输出:3
|
||||
// 解释:有三种方法可以爬到楼顶。
|
||||
// 1. 1 阶 + 1 阶 + 1 阶
|
||||
// 2. 1 阶 + 2 阶
|
||||
// 3. 2 阶 + 1 阶
|
||||
//
|
||||
// 提示:
|
||||
// - `1 <= n <= 45`
|
||||
//
|
||||
func climbStairs(n int) int {
|
||||
|
||||
}
|
||||
|
||||
func TestClimbStairs(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
n int
|
||||
want int
|
||||
}{
|
||||
{"example1", 2, 2},
|
||||
{"example2", 3, 3},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got := climbStairs(c.n)
|
||||
if got != c.want {
|
||||
t.Errorf("got %v, want %v", got, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user