137. Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.

Similar: 136. Single Number

260. Single Number III

 1 public class Solution {
 2     public int singleNumber(int[] nums) {
 3         int onece = 0, twice = 0, xthree = 0;
 4         for (int i = 0; i < nums.length; i++) {
 5             twice |= onece & nums[i];
 6             onece ^= nums[i];
 7             
 8             xthree = ~(onece & twice);
 9             onece &= xthree;
10             twice &= xthree;
11         }
12         return (onece | twice);
13     }
14 }

 

posted @ 2016-04-21 08:53  Joyce-Lee  阅读(177)  评论(0编辑  收藏  举报