From 72c01d1e910408ea9b46cf4928bbc890a61dd59c Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Sun, 14 Jun 2020 18:58:13 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E6=95=B0=E7=BB=84=E7=9B=B8=E5=85=B3.m?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blogs/Algorithm/剑指 Offer/数组相关.md | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/blogs/Algorithm/剑指 Offer/数组相关.md b/blogs/Algorithm/剑指 Offer/数组相关.md index 431f506..0ec813a 100644 --- a/blogs/Algorithm/剑指 Offer/数组相关.md +++ b/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}; + } +} +``` +