|
1 |
| -# [2936. Number of Equal Numbers Blocks](https://leetcode.cn/problems/number-of-equal-numbers-blocks) |
| 1 | +# [2936. 包含相等值数字块的数量](https://leetcode.cn/problems/number-of-equal-numbers-blocks) |
2 | 2 |
|
3 | 3 | [English Version](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README_EN.md)
|
4 | 4 |
|
5 | 5 | ## 题目描述
|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>You are given a <strong>0-indexed</strong> array of integers, <code>nums</code>. The following property holds for <code>nums</code>:</p> |
| 9 | +<p>给定一个整数数组 <code>nums</code>,其 <strong>下标从 0 开始</strong>。对于 <code>nums</code>,有以下性质:</p> |
10 | 10 |
|
11 | 11 | <ul>
|
12 |
| - <li>All occurrences of a value are adjacent. In other words, if there are two indices <code>i < j</code> such that <code>nums[i] == nums[j]</code>, then for every index <code>k</code> that <code>i < k < j</code>, <code>nums[k] == nums[i]</code>.</li> |
| 12 | + <li>所有相同值的元素都是相邻的。换句话说,如果存在两个下标 <code>i < j</code>,使得 <code>nums[i] == nums[j]</code>,那么对于所有下标 <code>k</code>,满足 <code>i < k < j</code>,都有 <code>nums[k] == nums[i]</code>。</li> |
13 | 13 | </ul>
|
14 | 14 |
|
15 |
| -<p>Since <code>nums</code> is a very large array, you are given an instance of the class <code>BigArray</code> which has the following functions:</p> |
| 15 | +<p>由于 <code>nums</code> 是一个非常大的数组,这里提供了一个 <code>BigArray</code> 类的实例,该实例具有以下函数:</p> |
16 | 16 |
|
17 | 17 | <ul>
|
18 |
| - <li><code>int at(long long index)</code>: Returns the value of <code>nums[i]</code>.</li> |
19 |
| - <li><code>void size()</code>: Returns <code>nums.length</code>.</li> |
| 18 | + <li><code>int at(long long index)</code>: 返回 <code>nums[i]</code> 的值。</li> |
| 19 | + <li><code>void size()</code>: 返回 <code>nums.length</code>。</li> |
20 | 20 | </ul>
|
21 | 21 |
|
22 |
| -<p>Let's partition the array into <strong>maximal</strong> blocks such that each block contains <strong>equal values</strong>. Return<em> the number of these blocks.</em></p> |
| 22 | +<p>让我们把数组分成 <strong>最大</strong> 的块,使得每个块包含 <strong>相等的值</strong>。返回这些块的数量。</p> |
23 | 23 |
|
24 |
| -<p><strong>Note</strong> that if you want to test your solution using a custom test, behavior for tests with <code>nums.length > 10</code> is undefined.</p> |
| 24 | +<p><strong>请注意</strong>,如果要使用自定义测试测试解决方案,对于 <code>nums.length > 10</code> 的测试行为是未定义的。</p> |
25 | 25 |
|
26 | 26 | <p> </p>
|
27 |
| -<p><strong class="example">Example 1:</strong></p> |
| 27 | + |
| 28 | +<p><strong>示例 1:</strong></p> |
28 | 29 |
|
29 | 30 | <pre>
|
30 |
| -<strong>Input:</strong> nums = [3,3,3,3,3] |
31 |
| -<strong>Output:</strong> 1 |
32 |
| -<strong>Explanation:</strong> There is only one block here which is the whole array (because all numbers are equal) and that is: [<u>3,3,3,3,3</u>]. So the answer would be 1. |
| 31 | +<b>输入:</b>nums = [3,3,3,3,3] |
| 32 | +<b>输出:</b>1 |
| 33 | +<b>解释:</b>这里只有一个块,即整个数组(因为所有数字都相等),即:[3,3,3,3,3]。因此答案是 1。 |
33 | 34 | </pre>
|
34 | 35 |
|
35 |
| -<p><strong class="example">Example 2:</strong></p> |
| 36 | +<p><b>示例 2:</b></p> |
36 | 37 |
|
37 | 38 | <pre>
|
38 |
| -<strong>Input:</strong> nums = [1,1,1,3,9,9,9,2,10,10] |
39 |
| -<strong>Output:</strong> 5 |
40 |
| -<strong>Explanation:</strong> There are 5 blocks here: |
41 |
| -Block number 1: [<u>1,1,1</u>,3,9,9,9,2,10,10] |
42 |
| -Block number 2: [1,1,1,<u>3</u>,9,9,9,2,10,10] |
43 |
| -Block number 3: [1,1,1,3,<u>9,9,9</u>,2,10,10] |
44 |
| -Block number 4: [1,1,1,3,9,9,9,<u>2</u>,10,10] |
45 |
| -Block number 5: [1,1,1,3,9,9,9,2,<u>10,10</u>] |
46 |
| -So the answer would be 5.</pre> |
47 |
| - |
48 |
| -<p><strong class="example">Example 3:</strong></p> |
| 39 | +<b>输入:</b>nums = [1,1,1,3,9,9,9,2,10,10] |
| 40 | +<b>输出:</b>5 |
| 41 | +<b>解释:</b>这里有 5 个块: |
| 42 | +块号 1: [<u>1,1,1</u>,3,9,9,9,2,10,10] |
| 43 | +块号 2: [1,1,1,<u>3</u>,9,9,9,2,10,10] |
| 44 | +块号 3: [1,1,1,3,<u>9,9,9</u>,2,10,10] |
| 45 | +块号 4: [1,1,1,3,9,9,9,<u>2</u>,10,10] |
| 46 | +块号 5: [1,1,1,3,9,9,9,2,<u>10,10</u>] |
| 47 | +因此答案是 5。</pre> |
| 48 | + |
| 49 | +<p><strong class="example">示例 3:</strong></p> |
49 | 50 |
|
50 | 51 | <pre>
|
51 |
| -<strong>Input:</strong> nums = [1,2,3,4,5,6,7] |
52 |
| -<strong>Output:</strong> 7 |
53 |
| -<strong>Explanation:</strong> Since all numbers are distinct, there are 7 blocks here and each element representing one block. So the answer would be 7. |
| 52 | +<b>输入:</b>nums = [1,2,3,4,5,6,7] |
| 53 | +<b>输出:</b>7 |
| 54 | +<b>解释:</b>由于所有数字都是不同的,这里有 7 个块,每个元素代表一个块。因此答案是 7。 |
54 | 55 | </pre>
|
55 | 56 |
|
56 | 57 | <p> </p>
|
57 |
| -<p><strong>Constraints:</strong></p> |
| 58 | + |
| 59 | +<p><strong>提示:</strong></p> |
58 | 60 |
|
59 | 61 | <ul>
|
60 | 62 | <li><code>1 <= nums.length <= 10<sup>15</sup></code></li>
|
61 | 63 | <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>
|
62 |
| - <li>The input is generated such that all equal values are adjacent.</li> |
63 |
| - <li>The sum of the elements of <code>nums</code> is at most <code>10<sup>15</sup></code>.</li> |
| 64 | + <li>在生成的输入中所有相同值的元素是相邻的。</li> |
| 65 | + <li><code>nums</code> 的所有元素之和最多为<meta charset="UTF-8" /> <code>10<sup>15</sup></code>。</li> |
64 | 66 | </ul>
|
65 | 67 |
|
66 | 68 | ## 解法
|
|
0 commit comments