题解 | #农场牛的标识III#
农场牛的标识III
https://www.nowcoder.com/practice/f8cf74a21aa4440595f007789ea6bd61
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型一维数组
* @return int整型
*/
public int twoCountNumber (int[] nums) {
// write code here
int ones = 0, twos = 0;
for (int num : nums) {
ones = (ones ^ num) & ~twos;
twos = (twos ^ num) & ~ones;
}
return twos;
}
}
位运算。

