420:强密码检验器
This commit is contained in:
parent
f20ce032ff
commit
776b62b9b6
40
src/main/java/leetcode/editor/cn/FactorialZerosLcci.java
Normal file
40
src/main/java/leetcode/editor/cn/FactorialZerosLcci.java
Normal 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)
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<p>设计一个算法,算出 n 阶乘有多少个尾随零。</p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong> 3
|
||||
<strong>输出:</strong> 0
|
||||
<strong>解释:</strong> 3! = 6, 尾数中没有零。</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre><strong>输入:</strong> 5
|
||||
<strong>输出:</strong> 1
|
||||
<strong>解释:</strong> 5! = 120, 尾数中有 1 个零.</pre>
|
||||
|
||||
<p><strong>说明: </strong>你算法的时间复杂度应为 <em>O</em>(log <em>n</em>)<em> </em>。</p>
|
||||
<div><div>Related Topics</div><div><li>数学</li></div></div><br><div><li>👍 66</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user