Given an integer n, return the number of trailing zeroes in n!.java
Note: Your solution should be in logarithmic time complexity.this
Credits:
Special thanks to @ts for adding this problem and creating all test cases.spa
注意時間複雜度.net
public class Solution { public int trailingZeroes(int n) { int num=0; int five = 1; //注意時間複雜度須要小,若是num =0; five =5;while(five<=n){five*=5; num +=n/five;}就time out 了 while(five<=n/5){ five *=5; num += n/five; } return num; } }