int countOneByBinary(int n)
{
int count = 0;
while(n != 0)
{
int tmp = n & 1;
if(tmp == 1)
count++;
n = n >> 1;
}
return count;
}
一個數字二進制中一的個數
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
leetcode刷題系列--442. Find All Duplicates in an Array
CodingBoy121
2020-06-23 09:04:28
leetcode刷題系列--206. Reverse Linked List 遞歸和非遞歸 c++實現
CodingBoy121
2020-06-23 09:04:09
leetcode刷題系列 448. Find All Numbers Disappeared in an Array
CodingBoy121
2020-02-22 09:47:14
leetcode刷題 447. Number of Boomerangs
CodingBoy121
2020-02-22 09:47:14
LeetCode 453. Minimum Moves to Equal Array Elements
CodingBoy121
2020-02-22 09:47:14
leetcode刷題系列--152. Maximum Product Subarray
CodingBoy121
2020-02-22 09:47:14
leetcode刷題--459. Repeated Substring Pattern
CodingBoy121
2020-02-22 09:47:14
leetcode刷題系列:不用加號實現a+b
CodingBoy121
2020-02-22 09:47:14
常見面試算法題整理
CodingBoy121
2020-02-22 09:47:03
leetcode刷題系列--442. Find All Duplicates in an Array
CodingBoy121
2020-06-23 09:04:28
leetcode刷題系列--206. Reverse Linked List 遞歸和非遞歸 c++實現
CodingBoy121
2020-06-23 09:04:09
leetcode刷題系列 448. Find All Numbers Disappeared in an Array
CodingBoy121
2020-02-22 09:47:14
leetcode刷題 447. Number of Boomerangs
CodingBoy121
2020-02-22 09:47:14
LeetCode 453. Minimum Moves to Equal Array Elements
CodingBoy121
2020-02-22 09:47:14
leetcode刷題系列--152. Maximum Product Subarray
CodingBoy121
2020-02-22 09:47:14
24小時熱門文章