* param n: As desciption * return: An integer, denote the number of trailing zeros in n! */publiclongtrailingZeros(longn){// write your code herereturnn /5==0?0: n /5+ trailingZeros(n /5); } }; C++版 class Solution { public: inttrailingZeroes(int n) { return n ==0?0: ...
首先除以5,然后再看因子中有多少个25,然后是125,依次类推。 classSolution {public:inttrailingZeroes(intn) {intzeros =0;intcurr =0;inti =1;while( (curr = n / pow(5,i)) >=1){ zeros+=curr; i++; }returnzeros; } };
172 Factorial Trailing Zeroes Medium JavaScript 173 Binary Search Tree Iterator Medium Rust 179 Largest Number Medium JavaScript 187 Repeated DNA Sequences Medium JavaScript 189 Rotate Array Medium JavaScript 190 Reverse Bits Easy JavaScript 191 Number of 1 Bits Easy JavaScript 198 House Robber Medium ...
AI代码解释 classSolution{publicinttrailingZeroes(int n){int ans=0;for(int i=5;i<=n;i+=5){for(int x=i;x%5==0;x/=5){++ans;}}returnans;}} 3、时间复杂度 时间复杂度:O(n) n!中的质因子5的个数为O(n),因此时间复杂度为O(n)。 空间复杂度:O(1) 只需要常量级的空间。 三、总结...
0172 Factorial Trailing Zeroes Go 41.6% Medium 0173 Binary Search Tree Iterator Go 69.0% Medium 0174 Dungeon Game Go 37.2% Hard 0175 Combine Two Tables 72.8% Easy 0176 Second Highest Salary 36.4% Medium 0177 Nth Highest Salary 37.3% Medium 0178 Rank Scores 59.7% Medium 0179 Largest...
14 Longest Common Prefix 34.1%Easy 20 Valid Parentheses 37.1%Easy 21 Merge Two Sorted Lists 48.6%Easy 26 Remove Duplicates from Sorted Array 41.7%Easy 27 Remove Element 45.4%Easy 28 Implement strStr() 32.8%Easy 35 Search Insert Position
0172 Factorial Trailing Zeroes Go 37.8% Easy 0173 Binary Search Tree Iterator Go 56.5% Medium 0174 Dungeon Game Go 32.3% Hard 0175 Combine Two Tables 60.7% Easy 0176 Second Highest Salary 31.6% Easy 0177 Nth Highest Salary 31.3% Medium 0178 Rank Scores 45.8% Medium 0179 Largest Num...
factorial-trailing-zeroes fan-zhuan-dan-ci-shun-xu-lcof fan-zhuan-lian-biao-lcof fancy-sequence fei-bo-na-qi-shu-lie-lcof fi9suh fibonacci-number filling-bookcase-shelves filter-elements-from-array final-prices-with-a-special-discount-in-a-shop final-value-of-variable-after-per...
Factorial Trailing Zeroes 173. Binary Search Tree Iterator 174. Dungeon Game 179. Largest Number 187. Repeated DNA Sequences 190. Reverse Bits 191. Number of 1 Bits 198. House Robber 199. Binary Tree Right Side View 200. Number of Islands 201. Bitwise AND of Numbers Range 202. Happy ...
Factorial Trailing Zeros Math\counting Generate Parentheses DFS fun Longest Inc Path in Matrix DFS + Memorized Search Binary Tree Inorder Traversal DFS->Iterative LC Forum Reverse Words in a String Note the copy trick! LC Forum House Robber DP: fun ! Paint Fence DP: fun ! Binary Search...