leetcode/lcci/08.01.Three Steps Problem/Solution.go

8 lines
144 B
Go

func waysToStep(n int) int {
const mod int = 1e9 + 7
a, b, c := 1, 2, 4
for i := 1; i < n; i++ {
a, b, c = b, c, (a+b+c)%mod
}
return a
}