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

172. Factorial Trailing Zeroes

2016-05-23 10:13 661 查看

172. Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Analysis:

参考:http://bookshadow.com/weblog/2014/12/30/leetcode-factorial-trailing-zeroes/http://www.cnblogs.com/ganganloveu/p/4193373.html

两个其实说的是一个意思,一种方法。

Source Code(C++):

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution {
public:
int trailingZeroes(int n) {
int five_counts=0;
while(n>0) {
five_counts += n/5;
n /= 5;
}
return five_counts;
}
};

int main() {
Solution sol;
cout << sol.trailingZeroes(50);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: