Skip to content

Commit 5630668

Browse files
committed
feat: add solutions to lc problems: No.2469~2472
* No.2469.Convert the Temperature * No.2470.Number of Subarrays With LCM Equal to K * No.2471.Minimum Number of Operations to Sort a Binary Tree by Level * No.2472.Maximum Number of Non-overlapping Palindrome Substrings
1 parent e637d4f commit 5630668

File tree

52 files changed

+2811
-21
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2811
-21
lines changed

solution/0000-0099/0040.Combination Sum II/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Solution:
6767
t.append(candidates[j])
6868
dfs(j + 1, s + candidates[j])
6969
t.pop()
70-
70+
7171
ans = []
7272
candidates.sort()
7373
t = []

solution/0200-0299/0295.Find Median from Data Stream/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Description
66

7-
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values.</p>
7+
<p>The <strong>median</strong> is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values.</p>
88

99
<ul>
1010
<li>For example, for <code>arr = [2,3,4]</code>, the median is <code>3</code>.</li>

solution/0700-0799/0790.Domino and Tromino Tiling/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Solution:
5656
else:
5757
ans = dfs(i + 2, j) + dfs(i + 2, j + 1)
5858
return ans % mod
59-
59+
6060
mod = 10**9 + 7
6161
return dfs(0, 0)
6262
```

solution/0700-0799/0791.Custom Sort String/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
我们还可以先统计 $s$ 中每个字符的出现次数,存储在 $cnt$ 数组中。
5757

58-
然后把字符串 $s$ 在 $order$ 中出现的字符按照 $order$ 中的顺序排序,添加到结果字符串中。然后把剩余的字符直接追加到结果字符串中
58+
然后把字符串 $s$ 在 $order$ 中出现的字符按照 $order$ 中的顺序排序,添加到结果字符串中。最后把剩余的字符直接追加到结果字符串中
5959

6060
时间复杂度 $O(m+n)$,空间复杂度 $O(m)$。其中 $m$ 和 $n$ 分别是字符串 $order$ 和 $s$ 的长度。
6161

solution/0800-0899/0863.All Nodes Distance K in Binary Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Solution:
9696
p[root] = fa
9797
dfs1(root.left, root)
9898
dfs1(root.right, root)
99-
99+
100100
def dfs2(root, fa, k):
101101
if root is None:
102102
return

solution/0900-0999/0901.Online Stock Span/README_EN.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
<p>Design an algorithm that collects daily price quotes for some stock and returns <strong>the span</strong> of that stock&#39;s price for the current day.</p>
88

9-
<p>The <strong>span</strong> of the stock&#39;s price today is defined as the maximum number of consecutive days (starting from today and going backward) for which the stock price was less than or equal to today&#39;s price.</p>
9+
<p>The <strong>span</strong> of the stock&#39;s price in one day is the maximum number of consecutive days (starting from that day and going backward) for which the stock price was less than or equal to the price of that day.</p>
1010

1111
<ul>
12-
<li>For example, if the price of a stock over the next <code>7</code> days were <code>[100,80,60,70,60,75,85]</code>, then the stock spans would be <code>[1,1,1,2,1,4,6]</code>.</li>
12+
<li>For example, if the prices of the stock in the last four days is <code>[7,2,1,2]</code> and the price of the stock today is <code>2</code>, then the span of today is <code>4</code> because starting from today, the price of the stock was less than or equal <code>2</code> for <code>4</code> consecutive days.</li>
13+
<li>Also, if the prices of the stock in the last four days is <code>[7,34,1,2]</code> and the price of the stock today is <code>8</code>, then the span of today is <code>3</code> because starting from today, the price of the stock was less than or equal <code>8</code> for <code>3</code> consecutive days.</li>
1314
</ul>
1415

1516
<p>Implement the <code>StockSpanner</code> class:</p>

solution/1300-1399/1366.Rank Teams by Votes/README_EN.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,42 @@
44

55
## Description
66

7-
<p>In a special ranking system, each voter gives a rank from highest to lowest to all teams participated in the competition.</p>
7+
<p>In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition.</p>
88

99
<p>The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.</p>
1010

11-
<p>Given an array of strings <code>votes</code> which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.</p>
11+
<p>You are given an array of strings <code>votes</code> which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.</p>
1212

13-
<p>Return <em>a string of all teams</em> <strong>sorted</strong> by the ranking system.</p>
13+
<p>Return <em>a string of all teams <strong>sorted</strong> by the ranking system</em>.</p>
1414

1515
<p>&nbsp;</p>
1616
<p><strong class="example">Example 1:</strong></p>
1717

1818
<pre>
1919
<strong>Input:</strong> votes = [&quot;ABC&quot;,&quot;ACB&quot;,&quot;ABC&quot;,&quot;ACB&quot;,&quot;ACB&quot;]
2020
<strong>Output:</strong> &quot;ACB&quot;
21-
<strong>Explanation:</strong> Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team.
22-
Team B was ranked second by 2 voters and was ranked third by 3 voters.
23-
Team C was ranked second by 3 voters and was ranked third by 2 voters.
24-
As most of the voters ranked C second, team C is the second team and team B is the third.
21+
<strong>Explanation:</strong>
22+
Team A was ranked first place by 5 voters. No other team was voted as first place, so team A is the first team.
23+
Team B was ranked second by 2 voters and ranked third by 3 voters.
24+
Team C was ranked second by 3 voters and ranked third by 2 voters.
25+
As most of the voters ranked C second, team C is the second team, and team B is the third.
2526
</pre>
2627

2728
<p><strong class="example">Example 2:</strong></p>
2829

2930
<pre>
3031
<strong>Input:</strong> votes = [&quot;WXYZ&quot;,&quot;XYZW&quot;]
3132
<strong>Output:</strong> &quot;XWYZ&quot;
32-
<strong>Explanation:</strong> X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn&#39;t have any votes as second position.
33+
<strong>Explanation:</strong>
34+
X is the winner due to the tie-breaking rule. X has the same votes as W for the first position, but X has one vote in the second position, while W does not have any votes in the second position.
3335
</pre>
3436

3537
<p><strong class="example">Example 3:</strong></p>
3638

3739
<pre>
3840
<strong>Input:</strong> votes = [&quot;ZMNAGUEDSJYLBOPHRQICWFXTVK&quot;]
3941
<strong>Output:</strong> &quot;ZMNAGUEDSJYLBOPHRQICWFXTVK&quot;
40-
<strong>Explanation:</strong> Only one voter so his votes are used for the ranking.
42+
<strong>Explanation:</strong> Only one voter, so their votes are used for the ranking.
4143
</pre>
4244

4345
<p>&nbsp;</p>

solution/1400-1499/1408.String Matching in an Array/README_EN.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## Description
66

7-
<p>Given an array of string <code>words</code>. Return all strings in <code>words</code> which is substring of another word in <strong>any</strong> order.&nbsp;</p>
7+
<p>Given an array of string <code>words</code>, return <em>all strings in </em><code>words</code><em> that is a <strong>substring</strong> of another word</em>. You can return the answer in <strong>any order</strong>.</p>
88

9-
<p>String <code>words[i]</code> is substring of <code>words[j]</code>,&nbsp;if&nbsp;can be obtained removing some characters to left and/or right side of <code>words[j]</code>.</p>
9+
<p>A <strong>substring</strong> is a contiguous sequence of characters within a string</p>
1010

1111
<p>&nbsp;</p>
1212
<p><strong class="example">Example 1:</strong></p>
@@ -31,6 +31,7 @@
3131
<pre>
3232
<strong>Input:</strong> words = [&quot;blue&quot;,&quot;green&quot;,&quot;bu&quot;]
3333
<strong>Output:</strong> []
34+
<strong>Explanation:</strong> No string of words is substring of another string.
3435
</pre>
3536

3637
<p>&nbsp;</p>
@@ -40,7 +41,7 @@
4041
<li><code>1 &lt;= words.length &lt;= 100</code></li>
4142
<li><code>1 &lt;= words[i].length &lt;= 30</code></li>
4243
<li><code>words[i]</code> contains only lowercase English letters.</li>
43-
<li>It&#39;s <strong>guaranteed</strong>&nbsp;that <code>words[i]</code>&nbsp;will be unique.</li>
44+
<li>All the strings of <code>words</code> are <strong>unique</strong>.</li>
4445
</ul>
4546

4647
## Solutions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# [2465. 不同的平均值数目](https://leetcode.cn/problems/number-of-distinct-averages)
2+
3+
[English Version](/solution/2400-2499/2465.Number%20of%20Distinct%20Averages/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <strong>偶数</strong>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;。</p>
10+
11+
<p>只要&nbsp;<code>nums</code> <strong>不是</strong>&nbsp;空数组,你就重复执行以下步骤:</p>
12+
13+
<ul>
14+
<li>找到&nbsp;<code>nums</code>&nbsp;中的最小值,并删除它。</li>
15+
<li>找到&nbsp;<code>nums</code>&nbsp;中的最大值,并删除它。</li>
16+
<li>计算删除两数的平均值。</li>
17+
</ul>
18+
19+
<p>两数 <code>a</code>&nbsp;和 <code>b</code>&nbsp;的 <strong>平均值</strong>&nbsp;&nbsp;<code>(a + b) / 2</code>&nbsp;。</p>
20+
21+
<ul>
22+
<li>比方说,<code>2</code>&nbsp;和&nbsp;<code>3</code>&nbsp;的平均值是&nbsp;<code>(2 + 3) / 2 = 2.5</code>&nbsp;。</li>
23+
</ul>
24+
25+
<p>返回上述过程能得到的 <strong>不同</strong>&nbsp;平均值的数目。</p>
26+
27+
<p><strong>注意</strong>&nbsp;,如果最小值或者最大值有重复元素,可以删除任意一个。</p>
28+
29+
<p>&nbsp;</p>
30+
31+
<p><strong>示例 1:</strong></p>
32+
33+
<pre><b>输入:</b>nums = [4,1,4,0,3,5]
34+
<b>输出:</b>2
35+
<strong>解释:</strong>
36+
1. 删除 0 和 5 ,平均值是 (0 + 5) / 2 = 2.5 ,现在 nums = [4,1,4,3] 。
37+
2. 删除 1 和 4 ,平均值是 (1 + 4) / 2 = 2.5 ,现在 nums = [4,3] 。
38+
3. 删除 3 和 4 ,平均值是 (3 + 4) / 2 = 3.5 。
39+
2.5 ,2.5 和 3.5 之中总共有 2 个不同的数,我们返回 2 。
40+
</pre>
41+
42+
<p><strong>示例 2:</strong></p>
43+
44+
<pre><b>输入:</b>nums = [1,100]
45+
<b>输出:</b>1
46+
<strong>解释:</strong>
47+
删除 1 和 100 后只有一个平均值,所以我们返回 1 。
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
52+
<p><strong>提示:</strong></p>
53+
54+
<ul>
55+
<li><code>2 &lt;= nums.length &lt;= 100</code></li>
56+
<li><code>nums.length</code>&nbsp;是偶数。</li>
57+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
58+
</ul>
59+
60+
## 解法
61+
62+
<!-- 这里可写通用的实现逻辑 -->
63+
64+
<!-- tabs:start -->
65+
66+
### **Python3**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
<!-- 这里可写当前语言的特殊实现逻辑 -->
77+
78+
```java
79+
80+
```
81+
82+
### **TypeScript**
83+
84+
```ts
85+
86+
```
87+
88+
### **...**
89+
90+
```
91+
92+
```
93+
94+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2465. Number of Distinct Averages](https://leetcode.com/problems/number-of-distinct-averages)
2+
3+
[中文文档](/solution/2400-2499/2465.Number%20of%20Distinct%20Averages/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length.</p>
8+
9+
<p>As long as <code>nums</code> is <strong>not</strong> empty, you must repetitively:</p>
10+
11+
<ul>
12+
<li>Find the minimum number in <code>nums</code> and remove it.</li>
13+
<li>Find the maximum number in <code>nums</code> and remove it.</li>
14+
<li>Calculate the average of the two removed numbers.</li>
15+
</ul>
16+
17+
<p>The <strong>average</strong> of two numbers <code>a</code> and <code>b</code> is <code>(a + b) / 2</code>.</p>
18+
19+
<ul>
20+
<li>For example, the average of <code>2</code> and <code>3</code> is <code>(2 + 3) / 2 = 2.5</code>.</li>
21+
</ul>
22+
23+
<p>Return<em> the number of <strong>distinct</strong> averages calculated using the above process</em>.</p>
24+
25+
<p><strong>Note</strong> that when there is a tie for a minimum or maximum number, any can be removed.</p>
26+
27+
<p>&nbsp;</p>
28+
<p><strong class="example">Example 1:</strong></p>
29+
30+
<pre>
31+
<strong>Input:</strong> nums = [4,1,4,0,3,5]
32+
<strong>Output:</strong> 2
33+
<strong>Explanation:</strong>
34+
1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].
35+
2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].
36+
3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.
37+
Since there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.
38+
</pre>
39+
40+
<p><strong class="example">Example 2:</strong></p>
41+
42+
<pre>
43+
<strong>Input:</strong> nums = [1,100]
44+
<strong>Output:</strong> 1
45+
<strong>Explanation:</strong>
46+
There is only one average to be calculated after removing 1 and 100, so we return 1.
47+
</pre>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li><code>2 &lt;= nums.length &lt;= 100</code></li>
54+
<li><code>nums.length</code> is even.</li>
55+
<li><code>0 &lt;= nums[i] &lt;= 100</code></li>
56+
</ul>
57+
58+
## Solutions
59+
60+
<!-- tabs:start -->
61+
62+
### **Python3**
63+
64+
```python
65+
66+
```
67+
68+
### **Java**
69+
70+
```java
71+
72+
```
73+
74+
### **TypeScript**
75+
76+
```ts
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->

0 commit comments

Comments
 (0)