Skip to content

Commit de2c7c2

Browse files
author
Shuo
authored
Merge pull request #396 from openset/develop
Add: Factorial Trailing Zeroes
2 parents 6dbe262 + f87fc5f commit de2c7c2

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
package factorial_trailing_zeroes
2+
3+
func trailingZeroes(n int) int {
4+
if n < 5 {
5+
return 0
6+
}
7+
return n/5 + trailingZeroes(n/5)
8+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
11
package factorial_trailing_zeroes
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input int
7+
expected int
8+
}
9+
10+
func TestTrailingZeroes(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: 3,
14+
expected: 0,
15+
},
16+
{
17+
input: 5,
18+
expected: 1,
19+
},
20+
{
21+
input: 7,
22+
expected: 1,
23+
},
24+
{
25+
input: 8,
26+
expected: 1,
27+
},
28+
{
29+
input: 10,
30+
expected: 2,
31+
},
32+
{
33+
input: 12,
34+
expected: 2,
35+
},
36+
{
37+
input: 25,
38+
expected: 6,
39+
},
40+
}
41+
for _, tc := range tests {
42+
output := trailingZeroes(tc.input)
43+
if output != tc.expected {
44+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)