Created
November 16, 2024 12:20
-
-
Save sAVItar02/6584d2ab5d85ca302b90c0934da991b8 to your computer and use it in GitHub Desktop.
Factorial Trailing Zeroes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} n | |
* @return {number} | |
*/ | |
var trailingZeroes = function(n) { | |
let x = 5; | |
let zeroes = 0; | |
while((n/x) >= 1) { | |
zeroes += Math.floor(n / x); | |
x = x * 5; | |
} | |
return zeroes; | |
}; | |
// GRE Math thingy | |
// Time: O(log(n)) | |
// Space: O(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment