|
|
|
@ -211,3 +211,24 @@ class Solution { |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
[56 - I. 数组中数字出现的次数](https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/) |
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
class Solution { |
|
|
|
|
public int[] singleNumbers(int[] nums) { |
|
|
|
|
int sum = 0; |
|
|
|
|
for (int i : nums) { |
|
|
|
|
sum = sum ^ i; |
|
|
|
|
} |
|
|
|
|
int flag = sum & (-sum); |
|
|
|
|
int res = 0; |
|
|
|
|
for (int i : nums) { |
|
|
|
|
if ((flag & i) != 0) { |
|
|
|
|
res = res ^ i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return new int[]{res, sum ^ res}; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|