Skip to content

Commit

Permalink
add NumberOf1.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
YuYinCUG committed Oct 31, 2016
1 parent ae57451 commit 85ecbe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NumberOf1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//二进制中1的个数

int Numberof1(int n)
{
int count = 0;
while(n)
{
n = (n - 1) & n;
++ count;
}
return count;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 剑指offer题集

- [面试题4:从尾到头打印链表](https://github.com/YuYinCUG/jianzhioffer/blob/master/PrintListReversingly.cpp)
- [面试题10:二进制中1的个数](https://github.com/YuYinCUG/jianzhioffer/blob/master/NumberOf1.cpp)
- [面试题9:斐波那契数列](https://github.com/YuYinCUG/jianzhioffer/blob/master/Fibonacci.cpp)
- [面试题13:在O(1)时间删除链表结点](https://github.com/YuYinCUG/jianzhioffer/blob/master/DeleteNode.cpp)
- [面试题16:反转链表](https://github.com/YuYinCUG/jianzhioffer/blob/master/ReverseList.cpp)
Expand Down

0 comments on commit 85ecbe1

Please sign in to comment.