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 9b9ca87

Browse files
committed
feat: add new leetcode problems: No.1850+
1 parent 611bf6d commit 9b9ca87

File tree

19 files changed

+874
-3
lines changed

19 files changed

+874
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# [1852. ](https://leetcode-cn.com/problems/distinct-numbers-in-each-subarray)
2+
3+
[English Version](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **Python3**
18+
19+
<!-- 这里可写当前语言的特殊实现逻辑 -->
20+
21+
```python
22+
23+
```
24+
25+
### **Java**
26+
27+
<!-- 这里可写当前语言的特殊实现逻辑 -->
28+
29+
```java
30+
31+
```
32+
33+
### **...**
34+
35+
```
36+
37+
```
38+
39+
<!-- tabs:end -->
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [1852. Distinct Numbers in Each Subarray](https://leetcode.com/problems/distinct-numbers-in-each-subarray)
2+
3+
[中文文档](/solution/1800-1899/1852.Distinct%20Numbers%20in%20Each%20Subarray/README.md)
4+
5+
## Description
6+
7+
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, you are asked to construct the array <code>ans</code> of size <code>n-k+1</code> where <code>ans[i]</code> is the number of <strong>distinct</strong> numbers in the subarray <code>nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]]</code>.</p>
8+
9+
10+
11+
<p>Return <em>the array </em><code>ans</code>.</p>
12+
13+
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>Example 1:</strong></p>
18+
19+
20+
21+
<pre>
22+
23+
<strong>Input:</strong> nums = [1,2,3,2,2,1,3], k = 3
24+
25+
<strong>Output:</strong> [3,2,2,2,3]
26+
27+
<strong>Explanation: </strong>The number of distinct elements in each subarray goes as follows:
28+
29+
- nums[0:2] = [1,2,3] so ans[0] = 3
30+
31+
- nums[1:3] = [2,3,2] so ans[1] = 2
32+
33+
- nums[2:4] = [3,2,2] so ans[2] = 2
34+
35+
- nums[3:5] = [2,2,1] so ans[3] = 2
36+
37+
- nums[4:6] = [2,1,3] so ans[4] = 3
38+
39+
</pre>
40+
41+
42+
43+
<p><strong>Example 2:</strong></p>
44+
45+
46+
47+
<pre>
48+
49+
<strong>Input:</strong> nums = [1,1,1,1,2,3,4], k = 4
50+
51+
<strong>Output:</strong> [1,2,3,4]
52+
53+
<strong>Explanation: </strong>The number of distinct elements in each subarray goes as follows:
54+
55+
- nums[0:3] = [1,1,1,1] so ans[0] = 1
56+
57+
- nums[1:4] = [1,1,1,2] so ans[1] = 2
58+
59+
- nums[2:5] = [1,1,2,3] so ans[2] = 3
60+
61+
- nums[3:6] = [1,2,3,4] so ans[3] = 4
62+
63+
</pre>
64+
65+
66+
67+
<p>&nbsp;</p>
68+
69+
<p><strong>Constraints:</strong></p>
70+
71+
72+
73+
<ul>
74+
<li><code>1 &lt;= k &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
75+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
76+
</ul>
77+
78+
## Solutions
79+
80+
<!-- tabs:start -->
81+
82+
### **Python3**
83+
84+
```python
85+
86+
```
87+
88+
### **Java**
89+
90+
```java
91+
92+
```
93+
94+
### **...**
95+
96+
```
97+
98+
```
99+
100+
<!-- tabs:end -->
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# [1853. ](https://leetcode-cn.com/problems/convert-date-format)
2+
3+
[English Version](/solution/1800-1899/1853.Convert%20Date%20Format/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
None
10+
11+
## 解法
12+
13+
<!-- 这里可写通用的实现逻辑 -->
14+
15+
<!-- tabs:start -->
16+
17+
### **SQL**
18+
19+
```sql
20+
21+
```
22+
23+
<!-- tabs:end -->
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# [1853. Convert Date Format](https://leetcode.com/problems/convert-date-format)
2+
3+
[中文文档](/solution/1800-1899/1853.Convert%20Date%20Format/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Days</code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| day | date |
14+
+-------------+------+
15+
day is the primary key for this table.
16+
</pre>
17+
18+
<p>&nbsp;</p>
19+
20+
<p>Write an SQL query to convert each date in <code>Days</code> into a string formatted as <code>&quot;day_name, month_name day, year&quot;</code>.</p>
21+
22+
<p>Return the result table <strong>in any order</strong>.</p>
23+
24+
<p>The query result format is in the following example:</p>
25+
26+
<p>&nbsp;</p>
27+
28+
<pre>
29+
Days table:
30+
+------------+
31+
| day |
32+
+------------+
33+
| 2022年04月12日 |
34+
| 2021年08月09日 |
35+
| 2020年06月26日 |
36+
+------------+
37+
38+
Result table:
39+
+-------------------------+
40+
| day |
41+
+-------------------------+
42+
| Tuesday, April 12, 2022 |
43+
| Monday, August 9, 2021 |
44+
| Friday, June 26, 2020 |
45+
+-------------------------+
46+
Please note that the output is case-sensitive.
47+
</pre>
48+
49+
50+
## Solutions
51+
52+
<!-- tabs:start -->
53+
54+
### **SQL**
55+
56+
```sql
57+
58+
```
59+
60+
<!-- tabs:end -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [1854. 人口最多的年份](https://leetcode-cn.com/problems/maximum-population-year)
2+
3+
[English Version](/solution/1800-1899/1854.Maximum%20Population%20Year/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个二维整数数组 <code>logs</code> ,其中每个 <code>logs[i] = [birth<sub>i</sub>, death<sub>i</sub>]</code> 表示第 <code>i</code> 个人的出生和死亡年份。</p>
10+
11+
<p>年份 <code>x</code> 的 <strong>人口</strong> 定义为这一年期间活着的人的数目。第 <code>i</code> 个人被计入年份 <code>x</code> 的人口需要满足:<code>x</code> 在闭区间 <code>[birth<sub>i</sub>, death<sub>i</sub> - 1]</code> 内。注意,人不应当计入他们死亡当年的人口中。</p>
12+
13+
<p>返回 <strong>人口最多</strong> 且 <strong>最早</strong> 的年份。</p>
14+
15+
<p> </p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><strong>输入:</strong>logs = [[1993,1999],[2000,2010]]
20+
<strong>输出:</strong>1993
21+
<strong>解释:</strong>人口最多为 1 ,而 1993 是人口为 1 的最早年份。
22+
</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<pre><strong>输入:</strong>logs = [[1950,1961],[1960,1971],[1970,1981]]
27+
<strong>输出:</strong>1960
28+
<strong>解释:</strong>
29+
人口最多为 2 ,分别出现在 1960 和 1970 。
30+
其中最早年份是 1960 。</pre>
31+
32+
<p> </p>
33+
34+
<p><strong>提示:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= logs.length &lt;= 100</code></li>
38+
<li><code>1950 &lt;= birth<sub>i</sub> &lt; death<sub>i</sub> &lt;= 2050</code></li>
39+
</ul>
40+
41+
42+
## 解法
43+
44+
<!-- 这里可写通用的实现逻辑 -->
45+
46+
<!-- tabs:start -->
47+
48+
### **Python3**
49+
50+
<!-- 这里可写当前语言的特殊实现逻辑 -->
51+
52+
```python
53+
54+
```
55+
56+
### **Java**
57+
58+
<!-- 这里可写当前语言的特殊实现逻辑 -->
59+
60+
```java
61+
62+
```
63+
64+
### **...**
65+
66+
```
67+
68+
```
69+
70+
<!-- tabs:end -->
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# [1854. Maximum Population Year](https://leetcode.com/problems/maximum-population-year)
2+
3+
[中文文档](/solution/1800-1899/1854.Maximum%20Population%20Year/README.md)
4+
5+
## Description
6+
7+
<p>You are given a 2D integer array <code>logs</code> where each <code>logs[i] = [birth<sub>i</sub>, death<sub>i</sub>]</code> indicates the birth and death years of the <code>i<sup>th</sup></code> person.</p>
8+
9+
<p>The <strong>population</strong> of some year <code>x</code> is the number of people alive during that year. The <code>i<sup>th</sup></code> person is counted in year <code>x</code>&#39;s population if <code>x</code> is in the <strong>inclusive</strong> range <code>[birth<sub>i</sub>, death<sub>i</sub> - 1]</code>. Note that the person is <strong>not</strong> counted in the year that they die.</p>
10+
11+
<p>Return <em>the <strong>earliest</strong> year with the <strong>maximum population</strong></em>.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> logs = [[1993,1999],[2000,2010]]
18+
<strong>Output:</strong> 1993
19+
<strong>Explanation:</strong> The maximum population is 1, and 1993 is the earliest year with this population.
20+
</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> logs = [[1950,1961],[1960,1971],[1970,1981]]
26+
<strong>Output:</strong> 1960
27+
<strong>Explanation:</strong>
28+
The maximum population is 2, and it had happened in years 1960 and 1970.
29+
The earlier year between them is 1960.</pre>
30+
31+
<p>&nbsp;</p>
32+
<p><strong>Constraints:</strong></p>
33+
34+
<ul>
35+
<li><code>1 &lt;= logs.length &lt;= 100</code></li>
36+
<li><code>1950 &lt;= birth<sub>i</sub> &lt; death<sub>i</sub> &lt;= 2050</code></li>
37+
</ul>
38+
39+
40+
## Solutions
41+
42+
<!-- tabs:start -->
43+
44+
### **Python3**
45+
46+
```python
47+
48+
```
49+
50+
### **Java**
51+
52+
```java
53+
54+
```
55+
56+
### **...**
57+
58+
```
59+
60+
```
61+
62+
<!-- tabs:end -->

0 commit comments

Comments
(0)

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