Update 数组相关.md

master
Omooo 4 years ago
parent 149456f975
commit 72c01d1e91
  1. 21
      blogs/Algorithm/剑指 Offer/数组相关.md

@ -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};
}
}
```

Loading…
Cancel
Save