From c26668abd470d206ece4c83960a7f731a4a85a05 Mon Sep 17 00:00:00 2001 From: "huangge1199@hotmail.com" Date: Sun, 18 Jul 2021 19:16:57 +0800 Subject: [PATCH] =?UTF-8?q?260:=E5=8F=AA=E5=87=BA=E7=8E=B0=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E7=9A=84=E6=95=B0=E5=AD=97=20III?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../leetcode/editor/cn/SingleNumberIii.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/leetcode/editor/cn/SingleNumberIii.java b/src/main/java/leetcode/editor/cn/SingleNumberIii.java index 5c87f55..733bea5 100644 --- a/src/main/java/leetcode/editor/cn/SingleNumberIii.java +++ b/src/main/java/leetcode/editor/cn/SingleNumberIii.java @@ -39,19 +39,34 @@ // πŸ‘ 416 πŸ‘Ž 0 package leetcode.editor.cn; + //260:εͺε‡ΊηŽ°δΈ€ζ¬‘ηš„ζ•°ε­— III -class SingleNumberIii{ +class SingleNumberIii { public static void main(String[] args) { //桋试代码 Solution solution = new SingleNumberIii().new Solution(); } + //εŠ›ζ‰£δ»£η  //leetcode submit region begin(Prohibit modification and deletion) -class Solution { - public int[] singleNumber(int[] nums) { - return null; + class Solution { + public int[] singleNumber(int[] nums) { + int xor = 0; + for (int i = 0; i < nums.length; i++) { + xor ^= nums[i]; + } + xor &= -xor; + int[] result = new int[2]; + for (int num : nums) { + if ((num & xor) == 0) { + result[0] ^= num; + } else { + result[1] ^= num; + } + } + return result; + } } -} //leetcode submit region end(Prohibit modification and deletion) } \ No newline at end of file