add new solutions
This commit is contained in:
parent
475d438db4
commit
1433bf4850
17 changed files with 394 additions and 0 deletions
24
solutions/0/q70/solution.go
Normal file
24
solutions/0/q70/solution.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package q70
|
||||
|
||||
func nWays(n, i int, cache []int) int {
|
||||
if i == n {
|
||||
return 1
|
||||
}
|
||||
if i > n {
|
||||
return 0
|
||||
}
|
||||
if cache == nil {
|
||||
cache = make([]int, n)
|
||||
} else if cache[i] != 0 {
|
||||
return cache[i]
|
||||
}
|
||||
ret := nWays(n, i+1, cache) + nWays(n, i+2, cache)
|
||||
cache[i] = ret
|
||||
return ret
|
||||
}
|
||||
|
||||
func climbStairs(n int) int {
|
||||
return nWays(n, 0, nil)
|
||||
}
|
||||
|
||||
var _ = climbStairs
|
||||
Loading…
Add table
Add a link
Reference in a new issue