Skip to content

Commit d451882

Browse files
authored
feat: add swift implementation to lcof problem: No.10.1 (#2856)
1 parent 5cc6315 commit d451882

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lcof/面试题10- I. 斐波那契数列/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ public class Solution {
177177
}
178178
```
179179

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

182201
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
func fib(_ n: Int) -> Int {
3+
var a = 0
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)