Leetcode: Factorial Trailing Zeroes, leetcodefactorial

Source: Internet
Author: User

Leetcode: Factorial Trailing Zeroes, leetcodefactorial

Given an integer n, return the number of trailing zeroes in n !. Note: Your solution shocould be in logarithmic time complexity.

Naive method: A simple method is to first calculate factorial of n, then count trailing 0 s in the result (We can count trailing 0 s by repeatedly dividing the factorial by 10 till the remainder is 0 ). however, the obvious disadvantage of this is: can cause overflow for a slightly bigger numbers as factorial of a number is a big number (See factorial of 20 given in above examples ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.