您的位置:首页 > 大数据 > 人工智能

刷一题Leetcode:Factorial Trailing Zeroes

2015-08-31 16:51 537 查看
Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Credits:

Special thanks to @ts for adding this problem and creating all test cases.

就是返回 n! 这个数里“零的个数”

[code]public class Solution {
    public int trailingZeroes(int n) {
        int result = 0;
        if (n < 0) {
            return -1;
        } else if (n < 5) {
            return 0;
        } else {
            while (n != 0) {
                n = n/5;
                result += n;

            }
        }
        return result;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: