刷题代码
Jason__Dong
这个作者很懒,什么都没留下…
展开
-
求二进制中1的个数
普通 (暴力) 方法:先求int位数,然后循环记录1的个数 int NumberOf1(int n) { int loopnum = 8 * sizeof(int), ans = 0; while(loopnum--){ ans += n&0x1; n = n>>1; }原创 2016-01-07 20:31:48 · 262 阅读 · 0 评论 -
LeetCode 172. Factorial Trailing Zeroes(阶乘结果尾数0的个数)---E
题目描述:Given an integer n, return the number of trailing zeroes in n!.Note : Your solution should be in logarithmic time complexity. 首先想到用组合数学的方法来算,n!中0的个数主要看的是1-n 各数的因数中2和5的次数,有多少对(2, 5),结果中就有多少个0,而原创 2016-03-22 08:42:18 · 333 阅读 · 0 评论