leetcode:Single Number II

来源:互联网 发布:嵌入式系统编程 扫描版 编辑:程序博客网 时间:2024/06/03 17:53


给出一个一组数组,除了特殊的一个外,里面的数字都出现了三次,

不使用额外的空间

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

转载之http://www.cnblogs.com/x1957/p/3373994.html

0 0
原创粉丝点击