420:强密码检验器

This commit is contained in:
轩辕龙儿 2022-04-02 16:57:14 +08:00
parent f20ce032ff
commit 776b62b9b6
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,40 @@
//设计一个算法算出 n 阶乘有多少个尾随零
//
// 示例 1:
//
// 输入: 3
//输出: 0
//解释: 3! = 6, 尾数中没有零
//
// 示例 2:
//
// 输入: 5
//输出: 1
//解释: 5! = 120, 尾数中有 1 个零.
//
// 说明: 你算法的时间复杂度应为 O(log n)
// Related Topics 数学 👍 66 👎 0
package leetcode.editor.cn;
//面试题 16.05:阶乘尾数
public class FactorialZerosLcci {
public static void main(String[] args) {
Solution solution = new FactorialZerosLcci().new Solution();
// TO TEST
}
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int trailingZeroes(int n) {
int count = 0;
while (n >= 5) {
count += n / 5;
n /= 5;
}
return count;
}
}
//leetcode submit region end(Prohibit modification and deletion)
}

View File

@ -0,0 +1,16 @@
<p>设计一个算法,算出 n 阶乘有多少个尾随零。</p>
<p><strong>示例 1:</strong></p>
<pre><strong>输入:</strong> 3
<strong>输出:</strong> 0
<strong>解释:</strong>&nbsp;3! = 6, 尾数中没有零。</pre>
<p><strong>示例&nbsp;2:</strong></p>
<pre><strong>输入:</strong> 5
<strong>输出:</strong> 1
<strong>解释:</strong>&nbsp;5! = 120, 尾数中有 1 个零.</pre>
<p><strong>说明: </strong>你算法的时间复杂度应为&nbsp;<em>O</em>(log&nbsp;<em>n</em>)<em>&nbsp;</em></p>
<div><div>Related Topics</div><div><li>数学</li></div></div><br><div><li>👍 66</li><li>👎 0</li></div>