Skip to content

Commit 98beaf4

Browse files
authored
feat: add swift implementation to lcof problem: No.10.2 (#2857)
1 parent d451882 commit 98beaf4

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lcof/面试题10- II. 青蛙跳台阶问题/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,25 @@ public class Solution {
174174
}
175175
```
176176

177+
#### Swift
178+
179+
```swift
180+
class Solution {
181+
func numWays(_ n: Int) -> Int {
182+
var a = 1
183+
var b = 1
184+
var count = n
185+
while count > 0 {
186+
let c = (a + b) % 1000000007
187+
a = b
188+
b = c
189+
count -= 1
190+
}
191+
return a
192+
}
193+
}
194+
```
195+
177196
<!-- tabs:end -->
178197

179198
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
func numWays(_ n: Int) -> Int {
3+
var a = 1
4+
var b = 1
5+
var count = n
6+
while count > 0 {
7+
let c = (a + b) % 1000000007
8+
a = b
9+
b = c
10+
count -= 1
11+
}
12+
return a
13+
}
14+
}

0 commit comments

Comments
 (0)