python int to binary and count the number of 1
2015-12-05 16:41
501 查看
import collections class Solution(object): def hammingWeight(self,n): """ :param n:int :return: int """ k="{0:b}".format(n) m=collections.Counter(k) return m['1'] p=Solution() print p.hammingWeight(11)
相关文章推荐
- Python爬虫入门四之Urllib库的高级用法
- python编码检测模块chardet
- Python爬虫入门三之Urllib库的基本使用
- Python爬虫入门二之爬虫基础了解
- Python爬虫入门一之综述
- [转]逻辑斯蒂回归 via python
- Python 爬虫学习系列教程----目录
- python--10行代码搞定词频统计
- python基础教程共60课-第5课变量
- python基础教程共60课-第4课输入
- Python——参数(2)
- python--删除队列重复元素
- win64位系统安装numpy
- python基本 if和function
- python实现关闭第三方窗口
- python 多线程/多进程
- 机器学习python实战——K近邻算法
- python学习笔记1--turtle
- numpy.random.shuffle(x)的用法
- python基本 tuple