顿搜
飞过闲红千叶,夕岸在哪
类目归类
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Input 25
Output 6
public int trailingZeroes(int n) {
if (n < 0) {
return -1;
}
int count = 0;
while (n != 0) {
n /= 5;
count += n;
}
return count;
}public class LeetCode0172 {
public int trailingZeroes(int n) {
if (n < 0) {
return -1;
}
int count = 0;
while (n != 0) {
n /= 5;
count += n;
}
return count;
}
public static void main(String[] args) {
LeetCode0172 leetcode = new LeetCode0172();
System.out.println(leetcode.trailingZeroes(25));
}
}