Factorial Trailing Zeroes - LeetCode
Can you solve this real interview question? Factorial Trailing Zeroes - Given an integer n, return the number of trailing zeroes in n!. Note that n! = n * (n - 1) * (n - 2) * ... * 3 * 2 * 1. Example 1: Input: n = 3 Output: 0 Explanation: 3! = 6, no tra
leetcode.com
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
from math import factorial
class Solution:
def trailingZeroes(self, n: int) -> int:
answer = 0
if n == 0:
return 0
else:
factorial_n = factorial(n)
while factorial_n%10 == 0:
factorial_n//=10
answer += 1
return answer
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2656. Maximum Sum With Exactly K Elements (0) | 2023.06.26 |
---|---|
leetcode 35. Search Insert Position (0) | 2023.06.26 |
leetcode 9. Palindrome Number (0) | 2023.06.26 |
백준 1152 단어의 개수 (0) | 2023.06.24 |
백준 1157 단어 공부 (0) | 2023.06.24 |
댓글