JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 1 public class Solution {
 2     public int singleNumber(int[] A) {
 3         // IMPORTANT: Please reset any member data you declared, as
 4         // the same Solution instance will be reused for each test case.
 5         int len = A.length;
 6         if(A == null)
 7             return 0;
 8         
 9         int[] result = new int[32];
10         int finalresult = 0;
11         for(int i = 0; i < 32; i++){
12             for(int j = 0; j < len; j++){
13                 if(((A[j] >> i) & 1) == 1)
14                     result[i] = (result[i] + 1) % 3;
15             }
16             finalresult |= (result[i] << i);
17         }
18         return finalresult;
19     }
20 }

every element appears n times except for one

 

 

posted on 2013-11-25 09:01  JasonChang  阅读(165)  评论(0编辑  收藏  举报