Skip to content

Commit 942ba71

Browse files
committed
leetcode.com 172. Factorial Trailing Zeroes
문제 링크: https://leetcode.com/problems/factorial-trailing-zeroes
1 parent 8aafd13 commit 942ba71

File tree

1 file changed

+20
-0
lines changed
  • leetcode.com 172. Factorial Trailing Zeroes

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def trailingZeroes(self, n: int) -> int:
3+
if n == 0:
4+
return 0
5+
6+
v = 1
7+
8+
for a in range(2, n + 1):
9+
v *= a
10+
11+
answer = 0
12+
13+
q, r = divmod(v, 10)
14+
15+
while r == 0:
16+
answer += 1
17+
v = q
18+
q, r = divmod(v, 10)
19+
20+
return answer

0 commit comments

Comments
 (0)