【LeetCode】172 - Factorial Trailing Zeroes
生活随笔
收集整理的這篇文章主要介紹了
【LeetCode】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.
Solution :計算包含的2和5組成的pair的個數,因為5的個數比2少,所以2和5組成的pair的個數由5的個數決定。?
- 觀察15!?=?有3個5(來自其中的5,?10,?15),?所以計算n/5就可以。 ?
- 但是25!?=?有6個5(有5個5來自其中的5,?10,?15,?20,?25,?另外還有1個5來自25=(5*5)的另外一個5),
?
轉載于:https://www.cnblogs.com/irun/p/4705421.html
總結
以上是生活随笔為你收集整理的【LeetCode】172 - Factorial Trailing Zeroes的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 复合主键@IdClass
- 下一篇: Eclipse 引导阮卓项目 No pr