2 Star 10 Fork 2

CG国斌 / myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
_172.java 635 Bytes
一键复制 编辑 原始数据 按行查看 历史
CG国斌 提交于 2020-11-01 11:08 . 中等难度:设计 & 数学
package com.hit.basmath.interview.top_interview_questions.medium_collection.math;
/**
* 172. 阶乘后的零
* <p>
* 给定一个整数 n,返回 n! 结果尾数中零的数量。
* <p>
* 示例 1:
* <p>
* 输入: 3
* 输出: 0
* 解释: 3! = 6, 尾数中没有零。
* <p>
* 示例 2:
* <p>
* 输入: 5
* 输出: 1
* 解释: 5! = 120, 尾数中有 1 个零.
* <p>
* 说明: 你算法的时间复杂度应为 O(log n) 。
*/
public class _172 {
public int trailingZeroes(int n) {
int ans = 0;
while (n > 0) {
n /= 5;
ans += n;
}
return ans;
}
}
Java
1
https://gitee.com/guobinhit/myleetcode.git
git@gitee.com:guobinhit/myleetcode.git
guobinhit
myleetcode
myleetcode
master

搜索帮助