Skip to content

Commit

Permalink
climb
Browse files Browse the repository at this point in the history
  • Loading branch information
pangzhiqiang committed Oct 2, 2020
1 parent 2c17643 commit f53c6fd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions controller/algorithm/threestepsproblem.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,24 @@ func waysToStep(n int) int {
}
return val[n]
}

//爬梯子 https://leetcode-cn.com/problems/climbing-stairs/
func climbStairs(n int) int {
if n == 0 {
return 0
}
if n == 1 {
return 1
}
if n == 2 {
return 2
}

val := make([]int, n+1)
val[1] = 1
val[2] = 2
for i := 3; i <= n; i++ {
val[i] = val[i-1] + val[i-2]
}
return val[n]
}

0 comments on commit f53c6fd

Please sign in to comment.