1. Description
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
2. Runtime Distribution
3. Submission Details
4. Example
Input 25
Output 6
5. Code
[restabs alignment="osc-tabs-right" responsive="true" icon="true" text="More" seltabcolor="#fdfdfd" seltabheadcolor="#000" tabheadcolor="blue"]
[restab title="Java" active="active"]
public int trailingZeroes(int n) { if (n < 0) { return -1; } int count = 0; while (n != 0) { n /= 5; count += n; } return count; }
[/restab]
[/restabs]
6.Test
[restabs alignment="osc-tabs-right" responsive="true" icon="true" text="More" seltabcolor="#fdfdfd" seltabheadcolor="#000" tabheadcolor="blue"]
[restab title="Java" active="active" ]
public class LeetCode0172 { public int trailingZeroes(int n) { if (n < 0) { return -1; } int count = 0; while (n != 0) { n /= 5; count += n; } return count; } public static void main(String[] args) { LeetCode0172 leetcode = new LeetCode0172(); System.out.println(leetcode.trailingZeroes(25)); } }
[/restab]
[/restabs]
Comments | NOTHING