Skip to content

Commit

Permalink
Time: 0 ms (100%), Space: 3.9 MB (8.85%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Oct 24, 2024
1 parent 68da60a commit 3ccb2c2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions 0070-climbing-stairs/0070-climbing-stairs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
func climbStairs(n int) int {
if n == 1 {
return 1
}

dp := make([]int, n)
dp[0], dp[1] = 1, 2
for i := 2; i < len(dp); i++ {
dp[i] = dp[i-1] + dp[i-2]
one, two := 1, 0
for i := 0; i < n; i++ {
temp := one
one = one + two
two = temp
}

return dp[n-1]
}
return one
}

0 comments on commit 3ccb2c2

Please sign in to comment.