관리 메뉴

솜씨좋은장씨

[leetCode] 172. Factorial Trailing Zeroes (Python) 본문

Programming/코딩 1일 1문제

[leetCode] 172. Factorial Trailing Zeroes (Python)

솜씨좋은장씨 2020. 7. 21. 01:47
728x90
반응형

Given an integer n, return the number of trailing zeroes in n!.

 

Example 1:

Input: 3
Output: 0
Explanation: 3! = 6, no trailing zero.

Example 2:

Input: 5
Output: 1
Explanation: 5! = 120, one trailing zero.

Note: Your solution should be in logarithmic time complexity.

 

Solution

class Solution:
    def trailingZeroes(self, n: int) -> int:
        answer = 0
        while n:
            n //= 5
            answer += n
        return answer

 

 

SOMJANG/CODINGTEST_PRACTICE

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

 

Comments