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;
}
}
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;
}
}
相关文章推荐
- Filter及FilterChain的使用详解
- MongoDB的学习--explain()和hint()
- Leetcode:Container With Most Water
- errorC2440:CMainFrame 无法从 NMTOOLBARA 转换为 NMHDR
- Leetcode 70 Climbing Stairs
- FromSIP Stack Training
- 535 5.7.8 Error: authentication failed: generic failure安装EMOS时SMTP测试报错
- Leetcode 217 Contains Duplicate
- Leetcode 219 Contains Duplicate II
- 百度地图 带AK可直接运行的baidumapsdk demo
- Data Guard FailOver
- Golang中的sync.WaitGroup用法实例
- Adb server didn't ACK, failed to start daemon
- 关于start-up routine 和 exec 和main()
- Win10预览版10163截图曝光,隶属winmain分支
- 【Leetcode】Contains Duplicate II #219
- 人工智能领域中声源定位的研究与发展------第二章 声源定位系统 (6)
- 人工智能领域中声源定位的研究与发展------第二章 声源定位系统 (5)
- 人工智能领域中声源定位的研究与发展------第二章 声源定位系统 (4)
- rails第一次做项目