Leetcode 191. Number of 1 Bits

題目描述:統計二進制中1的位數。 題目鏈接:191. Number of 1 Bits 初步想法就是沿用上題190的思路,右移n,然後不斷按位與操作來進行計數。 當然也可以用我以前面試的時候答的轉成字符串哈哈哈~ class Solution(object): def hammingWeight(self, n): """ :type n: int :rtype: int
相關文章
相關標籤/搜索