1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计异或值在范围内的数对有多少 [count-pairs-with-xor-in-a-range].html
2022-03-29 12:43:11 +08:00

43 lines
1.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code> (下标 <strong>从 0 开始</strong> 计数)以及两个整数:<code>low</code><code>high</code> ,请返回 <strong>漂亮数对</strong> 的数目。</p>
<p><strong>漂亮数对</strong> 是一个形如 <code>(i, j)</code> 的数对,其中 <code>0 &lt;= i &lt; j &lt; nums.length</code><code>low &lt;= (nums[i] XOR nums[j]) &lt;= high</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [1,4,2,7], low = 2, high = 6
<strong>输出:</strong>6
<strong>解释:</strong>所有漂亮数对 (i, j) 列出如下:
- (0, 1): nums[0] XOR nums[1] = 5
- (0, 2): nums[0] XOR nums[2] = 3
- (0, 3): nums[0] XOR nums[3] = 6
- (1, 2): nums[1] XOR nums[2] = 6
- (1, 3): nums[1] XOR nums[3] = 3
- (2, 3): nums[2] XOR nums[3] = 5
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [9,8,4,2,1], low = 5, high = 14
<strong>输出:</strong>8
<strong>解释:</strong>所有漂亮数对 (i, j) 列出如下:
- (0, 2): nums[0] XOR nums[2] = 13
  - (0, 3): nums[0] XOR nums[3] = 11
  - (0, 4): nums[0] XOR nums[4] = 8
  - (1, 2): nums[1] XOR nums[2] = 12
  - (1, 3): nums[1] XOR nums[3] = 10
  - (1, 4): nums[1] XOR nums[4] = 9
  - (2, 3): nums[2] XOR nums[3] = 6
  - (2, 4): nums[2] XOR nums[4] = 5</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= low &lt;= high &lt;= 2 * 10<sup>4</sup></code></li>
</ul>