int t=0;
t=~t;
请问为什么t会是-1;
Given an array of integers, every element appears three times except for one. Find that single one.Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
public int singleNumber(int[] A) {
int once = 0;
int twice = 0;
for (int i = 0; i < A.length; i++) {
twice |= once & A[i];
once ^= A[i];
int not_three = ~(once & twice);
once = not_three & once;
twice = not_three & twice;
}
return once;
}
这段代码怎么理解,求指导。 位运算学的好烂。。位运算
t=~t;
请问为什么t会是-1;
Given an array of integers, every element appears three times except for one. Find that single one.Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
public int singleNumber(int[] A) {
int once = 0;
int twice = 0;
for (int i = 0; i < A.length; i++) {
twice |= once & A[i];
once ^= A[i];
int not_three = ~(once & twice);
once = not_three & once;
twice = not_three & twice;
}
return once;
}
这段代码怎么理解,求指导。 位运算学的好烂。。位运算
解决方案 »
- 问一下java中多态的问题?
- 一个人喝n瓶饮料,每喝够三瓶可以重换一瓶,问他一共可以喝多少瓶
- 讨论一个问题:怎样避免一个类在不断地变化中对它相关联的类产生不利影响
- QQ群号4527614
- 编译不能通过,求助!
- 关于线程的疑惑,请指点,谢谢!
- ////一个十分具有挑战性的问题\\\\
- (RMI) java.lang.ClassNotFoundException: access to class loader denied ?????
- 在一个resin里怎么配置两个http的访问端口?
- 请问:用 ResultSet rs; rs.beforeFirst(); 如何定位到指定行 如:定位到19行,如何写,多谢!
- string池,常规区,代码区,堆栈是什么?
- java se swing下拉框的问题,急····求帮忙
各位全部取反:1111 1111 1111 1111 1111 1111 1111 1111 -1 的二进制补码表示为:1111 1111 1111 1111 1111 1111 1111 1111