Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Because the trailing zeros is only related to the number of 5 in n!, we can calculate this by the code below:

public int trailingZeroes(int n) { int rs = 0; while (n != 0) { rs += (n / 5); n /= 5; } return rs; }

Nice observation on the math characteristics of n!.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.