We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f118acb commit 3359f21Copy full SHA for 3359f21
src/factorialTrailingZeroes/factorialTrailingZeroes.cpp
@@ -64,7 +64,8 @@ class Solution {
64
public:
65
int trailingZeroes(int n) {
66
int result = 0;
67
- for(int i=5; n/i>0; i*=5){
+ //To avoid the integer overflow ( e.g. 'n >=1808548329' )
68
+ for(int i=5; n/i>0 && i <= INT_MAX/5; i*=5){
69
result += (n/i);
70
}
71
return result;
0 commit comments