Skip to content

Commit ef0b325

Browse files
committed
solve climbing stars
1 parent e6a08cf commit ef0b325

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

climbing-stairs/delight010.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
func climbStairs(_ n: Int) -> Int {
3+
var dictionary: [Int: Int] = [:]
4+
for i in 1...n {
5+
if i < 3 {
6+
dictionary[i] = i
7+
} else {
8+
if let value1 = dictionary[i - 1],
9+
let value2 = dictionary[i - 2] {
10+
dictionary[i] = value1 + value2
11+
}
12+
}
13+
}
14+
return dictionary[n] ?? 0
15+
}
16+
}
17+

0 commit comments

Comments
 (0)