[LeetCode OJ] Single Number II

题目地址:https://oj.leetcode.com/problems/single-number-ii/

题意:找出唯一一个不重复三次的数

解题思路:这题没O(N)的思路,就参考了晚上的答案

http://www.tuicool.com/articles/fAZZv2a

class Solution {
public:
    int singleNumber(int A[], int n) {
        int one=0,two=0,three=0;
        for(int i = 0; i<n; ++i){
            two |= one&A[i];
            one ^= A[i];
            three = one&two;
            one &=~three;
            two &=~three;
        }
        return one;
    }
};
点赞