1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-22 21:46:46 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-05-02 23:44:12 +08:00
parent 7ea03594b3
commit 2a71c78585
4790 changed files with 11696 additions and 10944 deletions

View File

@@ -12,7 +12,7 @@
"translatedContent": "<p>给你一个由非负整数组成的数组 <code>nums</code> 。另有一个查询数组 <code>queries</code> ,其中 <code>queries[i] = [x<sub>i</sub>, m<sub>i</sub>]</code> 。</p>\n\n<p>第 <code>i</code> 个查询的答案是 <code>x<sub>i</sub></code> 和任何 <code>nums</code> 数组中不超过 <code>m<sub>i</sub></code> 的元素按位异或(<code>XOR</code>)得到的最大值。换句话说,答案是 <code>max(nums[j] XOR x<sub>i</sub>)</code> ,其中所有 <code>j</code> 均满足 <code>nums[j] &lt;= m<sub>i</sub></code> 。如果 <code>nums</code> 中的所有元素都大于 <code>m<sub>i</sub></code>,最终答案就是 <code>-1</code> 。</p>\n\n<p>返回一个整数数组<em> </em><code>answer</code><em> </em>作为查询的答案,其中<em> </em><code>answer.length == queries.length</code><em> </em>且<em> </em><code>answer[i]</code><em> </em>是第<em> </em><code>i</code><em> </em>个查询的答案。</p>\n\n<p> </p>\n\n<p><strong>示例 1</strong></p>\n\n<pre><strong>输入:</strong>nums = [0,1,2,3,4], queries = [[3,1],[1,3],[5,6]]\n<strong>输出:</strong>[3,3,7]\n<strong>解释:</strong>\n1) 0 和 1 是仅有的两个不超过 1 的整数。0 XOR 3 = 3 而 1 XOR 3 = 2 。二者中的更大值是 3 。\n2) 1 XOR 2 = 3.\n3) 5 XOR 2 = 7.\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre><strong>输入:</strong>nums = [5,2,4,6,6,3], queries = [[12,4],[8,1],[6,3]]\n<strong>输出:</strong>[15,-1,5]\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 &lt;= nums.length, queries.length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>queries[i].length == 2</code></li>\n\t<li><code>0 &lt;= nums[j], x<sub>i</sub>, m<sub>i</sub> &lt;= 10<sup>9</sup></code></li>\n</ul>\n",
"isPaidOnly": false,
"difficulty": "Hard",
"likes": 126,
"likes": 127,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
@@ -149,7 +149,7 @@
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"14.8K\", \"totalSubmission\": \"29.5K\", \"totalAcceptedRaw\": 14796, \"totalSubmissionRaw\": 29469, \"acRate\": \"50.2%\"}",
"stats": "{\"totalAccepted\": \"14.9K\", \"totalSubmission\": \"29.7K\", \"totalAcceptedRaw\": 14946, \"totalSubmissionRaw\": 29711, \"acRate\": \"50.3%\"}",
"hints": [
"In problems involving bitwise operations, we often think on the bits level. In this problem, we can think that to maximize the result of an xor operation, we need to maximize the most significant bit, then the next one, and so on.",
"If there's some number in the array that is less than m and whose the most significant bit is different than that of x, then xoring with this number maximizes the most significant bit, so I know this bit in the answer is 1.",