您当前的位置: 首页 > 

对方正在debug

暂无认证

  • 3浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

阶乘后的零

对方正在debug 发布时间:2020-03-06 12:34:44 ,浏览量:3

题目:https://leetcode-cn.com/problems/factorial-trailing-zeroes/ 本质就是求n!中5的个数。 求法思路:先求含1个5的数的个数 n / 5 n/5 n/5,再求含2个5的数的个数 n / 5 2 n/5^2 n/52…

class Solution {
public:
    int trailingZeroes(int n) {
        int res = 0;
        while(n) {
            res += n/5;
            n /= 5;
        }
        return res;
    }
};
关注
打赏
1664895754
查看更多评论
立即登录/注册

微信扫码登录

0.0368s