Class Solution
-
- All Implemented Interfaces:
public final class Solution1803 - Count Pairs With XOR in a Range.
Hard
Given a (0-indexed) integer array
numsand two integerslowandhigh, return the number of nice pairs.A nice pair is a pair
(i, j)where0 <= i < j < nums.lengthandlow <= (nums[i] XOR nums[j]) <= high.Example 1:
Input: nums = 1,4,2,7, low = 2, high = 6
Output: 6
Explanation: All nice pairs (i, j) are as follows:
(0, 1): nums0 XOR nums1 = 5
(0, 2): nums0 XOR nums2 = 3
(0, 3): nums0 XOR nums3 = 6
(1, 2): nums1 XOR nums2 = 6
(1, 3): nums1 XOR nums3 = 3
(2, 3): nums2 XOR nums3 = 5
Example 2:
Input: nums = 9,8,4,2,1, low = 5, high = 14
Output: 8
Explanation: All nice pairs (i, j) are as follows:
(0, 2): nums0 XOR nums2 = 13
(0, 3): nums0 XOR nums3 = 11
(0, 4): nums0 XOR nums4 = 8
(1, 2): nums1 XOR nums2 = 12
(1, 3): nums1 XOR nums3 = 10
(1, 4): nums1 XOR nums4 = 9
(2, 3): nums2 XOR nums3 = 6
(2, 4): nums2 XOR nums4 = 5
Constraints:
<code>1 <= nums.length <= 2 * 10<sup>4</sup></code>
<code>1 <= numsi<= 2 * 10<sup>4</sup></code>
<code>1 <= low <= high <= 2 * 10<sup>4</sup></code>