mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>Given a <strong>(0-indexed)</strong> integer array <code>nums</code> and two integers <code>low</code> and <code>high</code>, return <em>the number of <strong>nice pairs</strong></em>.</p>
 | 
						||
 | 
						||
 | 
						||
 | 
						||
<p>A <strong>nice pair</strong> is a pair <code>(i, j)</code> where <code>0 <= i < j < nums.length</code> and <code>low <= (nums[i] XOR nums[j]) <= high</code>.</p>
 | 
						||
 | 
						||
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>Example 1:</strong></p>
 | 
						||
 | 
						||
 | 
						||
 | 
						||
<pre>
 | 
						||
 | 
						||
<strong>Input:</strong> nums = [1,4,2,7], low = 2, high = 6
 | 
						||
 | 
						||
<strong>Output:</strong> 6
 | 
						||
 | 
						||
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
 | 
						||
 | 
						||
    - (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>Example 2:</strong></p>
 | 
						||
 | 
						||
 | 
						||
 | 
						||
<pre>
 | 
						||
 | 
						||
<strong>Input:</strong> nums = [9,8,4,2,1], low = 5, high = 14
 | 
						||
 | 
						||
<strong>Output:</strong> 8
 | 
						||
 | 
						||
<strong>Explanation:</strong> All nice pairs (i, j) are as follows:
 | 
						||
 | 
						||
    - (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>Constraints:</strong></p>
 | 
						||
 | 
						||
 | 
						||
 | 
						||
<ul>
 | 
						||
 | 
						||
	<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
 | 
						||
 | 
						||
	<li><code>1 <= nums[i] <= 2 * 10<sup>4</sup></code></li>
 | 
						||
 | 
						||
	<li><code>1 <= low <= high <= 2 * 10<sup>4</sup></code></li>
 | 
						||
 | 
						||
</ul> |