leetcode刷題,總結,記錄 ,備忘 172

2021-07-08 21:56:12 字數 559 閱讀 2693

leetcode172 factorial trailing zeroes

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.

subscribe to see which companies asked this question

求階乘的尾數0的個數。首先想到的就是2x5,才會得0,又由於2的數量是肯定比5多的,所以只要計算5的數量即可,一開始我也比較天真,直接計算n / 5的結果,但是不行,因為還有25的情況,是5的2次方,需要多加個1,後面還有125,625等。所以使用迴圈每次除以5,將結果累加。

class solution 

return sum;

}};

leetcode刷題,總結,記錄,備忘 226

leetcode226題。invert binary tree 倒置二叉樹。想不到這題還有個梗,挺有意思的。我一開始自作聰明,想用乙個棧乙個佇列來做,用中序遍歷,把節點push進棧中,把節點的指push進佇列中,遍歷完之後,分別從棧頂和佇列頂拿出節點和數值,賦值。一開始想著感覺還挺對的,遞交了幾次都...

leetcode刷題,總結,記錄,備忘83

leetcode83.for example,given1 1 2,return1 2.given1 1 2 3 3,return1 2 3.不想說什麼了,比較簡單的題目,大爺的我提了6,7遍才過,因為中間有個流程一直疏忽了,如果當前項值域和下乙個結點的值域相同的話,在將下乙個結點刪掉,即連到下乙個...

leetcode刷題,總結,記錄,備忘202

leetcode202 credits special thanks to mithmatt and ts for adding this problem and creating all test cases.還是比較簡單的題目,雖然我提的次數比較多,又拉低了通過率,真是無情。每次計算如果得到結果...