|
1 |
| -# [3094. Guess the Number Using Bitwise Questions II](https://leetcode.cn/problems/guess-the-number-using-bitwise-questions-ii) |
| 1 | +# [3094. 使用按位查询猜测数字 II](https://leetcode.cn/problems/guess-the-number-using-bitwise-questions-ii) |
2 | 2 |
|
3 | 3 | [English Version](/solution/3000-3099/3094.Guess%20the%20Number%20Using%20Bitwise%20Questions%20II/README_EN.md)
|
4 | 4 |
|
|
8 | 8 |
|
9 | 9 | <!-- 这里写题目描述 -->
|
10 | 10 |
|
11 |
| -<p>There is a number <code>n</code> between <code>0</code> and <code>2<sup>30</sup> - 1</code> (both inclusive) that you have to find.</p> |
| 11 | +<p>你需要找到一个在 <code>0</code> 和 <code>2<sup>30</sup> - 1</code> (均包含)之间的数字 <code>n</code>。</p> |
12 | 12 |
|
13 |
| -<p>There is a pre-defined API <code>int commonBits(int num)</code> that helps you with your mission. But here is the challenge, every time you call this function, <code>n</code> changes in some way. But keep in mind, that you have to find the <strong>initial value of </strong><code>n</code>.</p> |
| 13 | +<p>有一个预定义的 API <code>int commonBits(int num)</code> 能帮助你完成任务。但挑战是每次你调用这个函数,<code>n</code> 都会以某种方式改变。但是记住,你需要找到的是<strong> </strong><code>n</code> 的 <strong>初始值</strong>。</p> |
14 | 14 |
|
15 |
| -<p><code>commonBits(int num)</code> acts as follows:</p> |
| 15 | +<p><code>commonBits(int num)</code> 的操作如下:</p> |
16 | 16 |
|
17 | 17 | <ul>
|
18 |
| - <li>Calculate <code>count</code> which is the number of bits where both <code>n</code> and <code>num</code> have the same value in that position of their binary representation.</li> |
| 18 | + <li>计算 <code>n</code> 和 <code>num</code> 的二进制表示中值相同的二进制位的位的数量 <code>count</code>。</li> |
19 | 19 | <li><code>n = n XOR num</code></li>
|
20 |
| - <li>Return <code>count</code>.</li> |
| 20 | + <li>返回 <code>count</code>。</li> |
21 | 21 | </ul>
|
22 | 22 |
|
23 |
| -<p>Return <em>the number</em> <code>n</code>.</p> |
| 23 | +<p>返回数字 <code>n</code>。</p> |
24 | 24 |
|
25 |
| -<p><strong>Note:</strong> In this world, all numbers are between <code>0</code> and <code>2<sup>30</sup> - 1</code> (both inclusive), thus for counting common bits, we see only the first 30 bits of those numbers.</p> |
| 25 | +<p><strong>注意:</strong>在这个世界中,所有数字都在 <code>0</code> 和 <code>2<sup>30</sup> - 1</code> 之间(均包含),因此在计算公共二进制位时,我们只看那些数字的前 30 个二进制位。</p> |
26 | 26 |
|
27 | 27 | <p> </p>
|
28 |
| -<p><strong class="example">Example 1: </strong></p> |
| 28 | + |
| 29 | +<p><strong class="example">示例 1:</strong></p> |
29 | 30 |
|
30 | 31 | <div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
31 |
| -<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> n = 31 </span></p> |
| 32 | +<p><strong>输入:</strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 31 </span></p> |
32 | 33 |
|
33 |
| -<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> 31 </span></p> |
| 34 | +<p><strong>输出:</strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">31 </span></p> |
34 | 35 |
|
35 |
| -<p><strong>Explanation: </strong> It can be proven that it's possible to find 31 using the provided API.</p> |
| 36 | +<p><strong>解释:</strong>可以证明,使用提供的 API 可以找到 31。</p> |
36 | 37 | </div>
|
37 | 38 |
|
38 |
| -<p><strong class="example">Example 2: </strong></p> |
| 39 | +<p><strong class="example">示例 2:</strong></p> |
39 | 40 |
|
40 | 41 | <div class="example-block" style="border-color: var(--border-tertiary); border-left-width: 2px; color: var(--text-secondary); font-size: .875rem; margin-bottom: 1rem; margin-top: 1rem; overflow: visible; padding-left: 1rem;">
|
41 |
| -<p><strong>Input: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> n = 33 </span></p> |
| 42 | +<p><strong>输入:</strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">n = 33 </span></p> |
42 | 43 |
|
43 |
| -<p><strong>Output: </strong> <span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;"> 33 </span></p> |
| 44 | +<p><strong>输出:</strong><span class="example-io" style="font-family: Menlo,sans-serif; font-size: 0.85rem;">33 </span></p> |
44 | 45 |
|
45 |
| -<p><strong>Explanation: </strong> It can be proven that it's possible to find 33 using the provided API.</p> |
| 46 | +<p><strong>解释:</strong>可以证明,使用提供的 API 可以找到 33。</p> |
46 | 47 | </div>
|
47 | 48 |
|
48 | 49 | <p> </p>
|
49 |
| -<p><strong>Constraints:</strong></p> |
| 50 | + |
| 51 | +<p><strong>提示:</strong></p> |
50 | 52 |
|
51 | 53 | <ul>
|
52 | 54 | <li><code>0 <= n <= 2<sup>30</sup> - 1</code></li>
|
53 | 55 | <li><code>0 <= num <= 2<sup>30</sup> - 1</code></li>
|
54 |
| - <li>If you ask for some <code>num</code> out of the given range, the output wouldn't be reliable.</li> |
| 56 | + <li>如果你查询的 <code>num</code> 超出了给定的范围,输出将会是不可靠的。</li> |
55 | 57 | </ul>
|
56 | 58 |
|
57 | 59 | ## 解法
|
|
0 commit comments