Skip to content

Commit b8c0495

Browse files
authored
feat: add swift implementation to lcci problem: No.16.05 (doocs#2728)
1 parent 22e3fc6 commit b8c0495

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lcci/16.05.Factorial Zeros/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ function trailingZeroes(n: number): number {
9393
}
9494
```
9595

96+
```swift
97+
class Solution {
98+
func trailingZeroes(_ n: Int) -> Int {
99+
var count = 0
100+
var number = n
101+
while number > 0 {
102+
number /= 5
103+
count += number
104+
}
105+
return count
106+
}
107+
}
108+
```
109+
96110
<!-- tabs:end -->
97111

98112
<!-- end -->

lcci/16.05.Factorial Zeros/README_EN.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ function trailingZeroes(n: number): number {
101101
}
102102
```
103103

104+
```swift
105+
class Solution {
106+
func trailingZeroes(_ n: Int) -> Int {
107+
var count = 0
108+
var number = n
109+
while number > 0 {
110+
number /= 5
111+
count += number
112+
}
113+
return count
114+
}
115+
}
116+
```
117+
104118
<!-- tabs:end -->
105119

106120
<!-- end -->
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
func trailingZeroes(_ n: Int) -> Int {
3+
var count = 0
4+
var number = n
5+
while number > 0 {
6+
number /= 5
7+
count += number
8+
}
9+
return count
10+
}
11+
}

0 commit comments

Comments
 (0)