Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
solution:
zero comes from 2*5, and number of 2 is less than 5. So we can only count the number of 5 contained in n!.
public int trailingZeroes(int n) { if(n<5) return 0; int count = 0; while(n/5 !=0){ n/=5; count +=n; } return count; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-17 21:10:58