From 7efb0980b6c2b6154ec33cadfe731372acaa18ac Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Wed, 2 Jun 2021 16:38:02 +0800 Subject: [PATCH] =?UTF-8?q?1803:=E7=BB=9F=E8=AE=A1=E5=BC=82=E6=88=96?= =?UTF-8?q?=E5=80=BC=E5=9C=A8=E8=8C=83=E5=9B=B4=E5=86=85=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E5=AF=B9=E6=9C=89=E5=A4=9A=E5=B0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/leetcode/editor/cn/CountPairsWithXorInARange.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/leetcode/editor/cn/CountPairsWithXorInARange.java b/src/main/java/leetcode/editor/cn/CountPairsWithXorInARange.java index 07418a9..08552c9 100644 --- a/src/main/java/leetcode/editor/cn/CountPairsWithXorInARange.java +++ b/src/main/java/leetcode/editor/cn/CountPairsWithXorInARange.java @@ -57,6 +57,7 @@ public class CountPairsWithXorInARange { //leetcode submit region begin(Prohibit modification and deletion) class Solution { public int countPairs(int[] nums, int low, int high) { + // xors[index] : nums[0]^数组中其他值=index int[] xors = new int[32768]; int count = 0; for (int i = 1; i < nums.length; i++) { @@ -66,6 +67,10 @@ public class CountPairsWithXorInARange { } xors[num]++; } + // xor ^ j = index = nums[0] ^ 数组中其他值 + // xor ^ j = nums[0] ^ 数组中其他值 + // xor ^ j ^ (nums[0] ^ 数组中其他值 ^ j) = nums[0] ^ 数组中其他值 ^ (nums[0] ^ 数组中其他值 ^ j) + // nums[i] ^ 数组中其他值 = j for (int i = 1; i < nums.length; i++) { int xor = nums[0] ^ nums[i]; xors[xor]--;