leetcode 172. 阶乘后的零[【认真你就输了】

    xiaoxiao2022-07-14  170

    执行用时 : 4 ms, 在Factorial Trailing Zeroes的C++提交中击败了98.02% 的用户

    内存消耗 : 8.2 MB, 在Factorial Trailing Zeroes的C++提交中击败了76.37%的用户

    解题:

    5的数量少于2,4,6,  8。

    所以5是基准。千万不要乘,不要急,多想想。

    第一印象往往是不准的

     

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

     

    最新回复(0)