思路

  • 仅有2 * 5才能得末尾有0;
  • 2的个数比5的个数多很多,所以,即是有因数中5的个数。

解答

  1. public class Solution {
  2. public int trainingZeros(int n) {
  3. int ans = 0;
  4. while (n > 0) {
  5. ans += n / 5;
  6. n = n / 5;
  7. }
  8. return ans;
  9. }
  10. }