您的位置:首页 > 大数据 > 人工智能

172_Factorial Trailing Zeroes

2015-07-04 19:05 387 查看
题目地址:https://leetcode.com/problems/factorial-trailing-zeroes/

public class FactorialTrailingZeroes_172 {
/**
* 5出现的次数比2多
*
* 5 2 -> 10
* 25 4 -> 100
* 125 8 -> 1000
* 625 16 -> 10000
*
* http://www.cnblogs.com/Lyush/archive/2012/08/06/2624549.html */
public int trailingZeroes(int n) {
int zeros=0;
int five=5;
while(n>=five){
zeros+=n/five;
if(five>Integer.MAX_VALUE/5)
break;
five*=5;
}
return zeros;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: