Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d5fd51e

Browse files
chore: update lc problems (#1971)
1 parent dce769c commit d5fd51e

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# [2936. Number of Equal Numbers Blocks](https://leetcode.cn/problems/number-of-equal-numbers-blocks)
2+
3+
[English Version](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
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>
10+
11+
<ul>
12+
<li>All occurrences of a value are adjacent. In other words, if there are two indices <code>i &lt; j</code> such that <code>nums[i] == nums[j]</code>, then for every index <code>k</code> that <code>i &lt; k &lt; j</code>, <code>nums[k] == nums[i]</code>.</li>
13+
</ul>
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>
16+
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>
20+
</ul>
21+
22+
<p>Let&#39;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>
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 &gt; 10</code> is undefined.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong class="example">Example 1:</strong></p>
28+
29+
<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.
33+
</pre>
34+
35+
<p><strong class="example">Example 2:</strong></p>
36+
37+
<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>
49+
50+
<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.
54+
</pre>
55+
56+
<p>&nbsp;</p>
57+
<p><strong>Constraints:</strong></p>
58+
59+
<ul>
60+
<li><code>1 &lt;= nums.length &lt;= 10<sup>15</sup></code></li>
61+
<li><code>1 &lt;= nums[i] &lt;= 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&nbsp;<code>nums</code>&nbsp;is at most&nbsp;<code>10<sup>15</sup></code>.</li>
64+
</ul>
65+
66+
## 解法
67+
68+
<!-- 这里可写通用的实现逻辑 -->
69+
70+
<!-- tabs:start -->
71+
72+
### **Python3**
73+
74+
<!-- 这里可写当前语言的特殊实现逻辑 -->
75+
76+
```python
77+
78+
```
79+
80+
### **Java**
81+
82+
<!-- 这里可写当前语言的特殊实现逻辑 -->
83+
84+
```java
85+
86+
```
87+
88+
### **C++**
89+
90+
```cpp
91+
92+
```
93+
94+
### **Go**
95+
96+
```go
97+
98+
```
99+
100+
### **...**
101+
102+
```
103+
104+
```
105+
106+
<!-- tabs:end -->
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# [2936. Number of Equal Numbers Blocks](https://leetcode.com/problems/number-of-equal-numbers-blocks)
2+
3+
[中文文档](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> array of integers, <code>nums</code>. The following property holds for <code>nums</code>:</p>
8+
9+
<ul>
10+
<li>All occurrences of a value are adjacent. In other words, if there are two indices <code>i &lt; j</code> such that <code>nums[i] == nums[j]</code>, then for every index <code>k</code> that <code>i &lt; k &lt; j</code>, <code>nums[k] == nums[i]</code>.</li>
11+
</ul>
12+
13+
<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>
14+
15+
<ul>
16+
<li><code>int at(long long index)</code>: Returns the value of <code>nums[i]</code>.</li>
17+
<li><code>void size()</code>: Returns <code>nums.length</code>.</li>
18+
</ul>
19+
20+
<p>Let&#39;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>
21+
22+
<p><strong>Note</strong> that if you want to test your solution using a custom test, behavior for tests with <code>nums.length &gt; 10</code> is undefined.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong class="example">Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> nums = [3,3,3,3,3]
29+
<strong>Output:</strong> 1
30+
<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+
</pre>
32+
33+
<p><strong class="example">Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> nums = [1,1,1,3,9,9,9,2,10,10]
37+
<strong>Output:</strong> 5
38+
<strong>Explanation:</strong> There are 5 blocks here:
39+
Block number 1: [<u>1,1,1</u>,3,9,9,9,2,10,10]
40+
Block number 2: [1,1,1,<u>3</u>,9,9,9,2,10,10]
41+
Block number 3: [1,1,1,3,<u>9,9,9</u>,2,10,10]
42+
Block number 4: [1,1,1,3,9,9,9,<u>2</u>,10,10]
43+
Block number 5: [1,1,1,3,9,9,9,2,<u>10,10</u>]
44+
So the answer would be 5.</pre>
45+
46+
<p><strong class="example">Example 3:</strong></p>
47+
48+
<pre>
49+
<strong>Input:</strong> nums = [1,2,3,4,5,6,7]
50+
<strong>Output:</strong> 7
51+
<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+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>1 &lt;= nums.length &lt;= 10<sup>15</sup></code></li>
59+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
60+
<li>The input is generated such that all equal values are adjacent.</li>
61+
<li>The sum of the elements of&nbsp;<code>nums</code>&nbsp;is at most&nbsp;<code>10<sup>15</sup></code>.</li>
62+
</ul>
63+
64+
## Solutions
65+
66+
<!-- tabs:start -->
67+
68+
### **Python3**
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
```java
77+
78+
```
79+
80+
### **C++**
81+
82+
```cpp
83+
84+
```
85+
86+
### **Go**
87+
88+
```go
89+
90+
```
91+
92+
### **...**
93+
94+
```
95+
96+
```
97+
98+
<!-- tabs:end -->

‎solution/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,7 @@
29462946
| 2933 | [高访问员工](/solution/2900-2999/2933.High-Access%20Employees/README.md) | | 中等 | 第 371 场周赛 |
29472947
| 2934 | [最大化数组末位元素的最少操作次数](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README.md) | | 中等 | 第 371 场周赛 |
29482948
| 2935 | [找出强数对的最大异或值 II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README.md) | | 困难 | 第 371 场周赛 |
2949+
| 2936 | [Number of Equal Numbers Blocks](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README.md) | | 中等 | 🔒 |
29492950

29502951
## 版权
29512952

‎solution/README_EN.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2944,6 +2944,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
29442944
| 2933 | [High-Access Employees](/solution/2900-2999/2933.High-Access%20Employees/README_EN.md) | | Medium | Weekly Contest 371 |
29452945
| 2934 | [Minimum Operations to Maximize Last Elements in Arrays](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README_EN.md) | | Medium | Weekly Contest 371 |
29462946
| 2935 | [Maximum Strong Pair XOR II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README_EN.md) | | Hard | Weekly Contest 371 |
2947+
| 2936 | [Number of Equal Numbers Blocks](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README_EN.md) | | Medium | 🔒 |
29472948

29482949
## Copyright
29492950

‎solution/summary.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,3 +2993,4 @@
29932993
- [2933.高访问员工](/solution/2900-2999/2933.High-Access%20Employees/README.md)
29942994
- [2934.最大化数组末位元素的最少操作次数](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README.md)
29952995
- [2935.找出强数对的最大异或值 II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README.md)
2996+
- [2936.Number of Equal Numbers Blocks](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README.md)

‎solution/summary_en.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,3 +2993,4 @@
29932993
- [2933.High-Access Employees](/solution/2900-2999/2933.High-Access%20Employees/README_EN.md)
29942994
- [2934.Minimum Operations to Maximize Last Elements in Arrays](/solution/2900-2999/2934.Minimum%20Operations%20to%20Maximize%20Last%20Elements%20in%20Arrays/README_EN.md)
29952995
- [2935.Maximum Strong Pair XOR II](/solution/2900-2999/2935.Maximum%20Strong%20Pair%20XOR%20II/README_EN.md)
2996+
- [2936.Number of Equal Numbers Blocks](/solution/2900-2999/2936.Number%20of%20Equal%20Numbers%20Blocks/README_EN.md)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /