LeetCode之Single Number II
2014-03-30 18:50
344 查看
int singleNumber(int A[], int n)//Single Number II { int b; int count[sizeof(int)*8]={}; for(int j=0;j<32;j++) { for (int i=0;i<n;i++) { b=1; b&=(A[i]>>j); count[j]+=b; } } b=0; for (int k=0;k<32;k++) { if (count[k]%3!=0) {b+=((count[k]%3)<<k); } } return b; }
相关文章推荐
- Palindrome Number
- Max Points on a Line
- Evaluate Reverse Polish Notation
- Sort List
- Insertion Sort List
- LRU Cache
- Binary Tree Postorder Traversal
- Binary Tree Preorder Traversal
- Reorder List
- Linked List Cycle
- Linked List Cycle II
- Word Break
- Word Break II
- Copy List with Random Pointer
- Single Number
- Single Number II
- Candy
- Gas Station
- Clone Graph
- Palindrome Partitioning