mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 18:44:44 +01:00
20201114
This commit is contained in:
@@ -6,6 +6,7 @@ func main() {
|
||||
fmt.Println(isCompliance([]int{2, 3, 3, 2, 4}))
|
||||
fmt.Println(isCompliance([]int{3, 3, 2, 4}))
|
||||
fmt.Println(isCompliance([]int{4, 5, 1, 2}))
|
||||
fmt.Println(isCompliance([]int{5, 1, 2, 3}))
|
||||
}
|
||||
|
||||
func isCompliance(nums []int) bool {
|
||||
|
||||
@@ -21,6 +21,11 @@ func Test_isCompliance(t *testing.T) {
|
||||
args{[]int{4, 2, 1}},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"example_3",
|
||||
args{[]int{5, 1, 2, 3}},
|
||||
true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
23
20201114/main.go
Normal file
23
20201114/main.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
var steps = []int{1, 2}
|
||||
|
||||
func main() {
|
||||
fmt.Println("count:", climbingStairs(100, steps))
|
||||
}
|
||||
|
||||
func climbingStairs(n int, step []int) int {
|
||||
if n <= 1 {
|
||||
return 1
|
||||
}
|
||||
pre1 := 1
|
||||
pre2 := 1
|
||||
for i := 2; i <= n; i++ {
|
||||
cur := pre1 + pre2
|
||||
pre2 = pre1
|
||||
pre1 = cur
|
||||
}
|
||||
return pre1
|
||||
}
|
||||
33
20201114/main_test.go
Normal file
33
20201114/main_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_climbingStairs(t *testing.T) {
|
||||
type args struct {
|
||||
n int
|
||||
step []int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
}{
|
||||
{
|
||||
"1",
|
||||
args{2, []int{1, 2}},
|
||||
2,
|
||||
},
|
||||
{
|
||||
"3",
|
||||
args{3, []int{1, 2}},
|
||||
3,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := climbingStairs(tt.args.n, tt.args.step); got != tt.want {
|
||||
t.Errorf("climbingStairs() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user