Skip to content

Commit 574890b

Browse files
committed
feat: add new lc problems
1 parent d6d2f6c commit 574890b

File tree

13 files changed

+221
-51
lines changed

13 files changed

+221
-51
lines changed

solution/1500-1599/1581.Customer Who Visited but Did Not Make Any Transactions/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This table contains information about the transactions made during the visit_id.
3535

3636
<p>&nbsp;</p>
3737

38-
<p>Write an SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.</p>
38+
<p>Write a&nbsp;SQL query to find the IDs of the users who visited without making any transactions and the number of times they made these types of visits.</p>
3939

4040
<p>Return the result table sorted in <strong>any order</strong>.</p>
4141

solution/1800-1899/1825.Finding MK Average/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66

77
<!-- 这里写题目描述 -->
88

9-
<p>给你两个整数 <code>m</code> 和 <code>k</code> ,以及数据流形式的若干整数。你需要实现一个数据结构,计算这个数据流的 <b>MK 平均值</b> 。</p>
9+
<p>给你两个整数&nbsp;<code>m</code>&nbsp;&nbsp;<code>k</code>&nbsp;,以及数据流形式的若干整数。你需要实现一个数据结构,计算这个数据流的 <b>MK 平均值</b>&nbsp;。</p>
1010

11-
<p><strong>MK 平均值</strong> 按照如下步骤计算:</p>
11+
<p><strong>MK 平均值</strong>&nbsp;按照如下步骤计算:</p>
1212

1313
<ol>
14-
<li>如果数据流中的整数少于 <code>m</code> 个,<strong>MK 平均值</strong> 为 <code>-1</code> ,否则将数据流中最后 <code>m</code> 个元素拷贝到一个独立的容器中。</li>
15-
<li>从这个容器中删除最小的 <code>k</code> 个数和最大的 <code>k</code> 个数。</li>
16-
<li>计算剩余元素的平均值,并 <strong>向下取整到最近的整数</strong> 。</li>
14+
<li>如果数据流中的整数少于 <code>m</code>&nbsp;个,<strong>MK 平均值</strong>&nbsp;为 <code>-1</code>&nbsp;,否则将数据流中最后 <code>m</code>&nbsp;个元素拷贝到一个独立的容器中。</li>
15+
<li>从这个容器中删除最小的 <code>k</code>&nbsp;个数和最大的 <code>k</code>&nbsp;个数。</li>
16+
<li>计算剩余元素的平均值,并 <strong>向下取整到最近的整数</strong>&nbsp;。</li>
1717
</ol>
1818

19-
<p>请你实现 <code>MKAverage</code> 类:</p>
19+
<p>请你实现&nbsp;<code>MKAverage</code>&nbsp;类:</p>
2020

2121
<ul>
22-
<li><code>MKAverage(int m, int k)</code> 用一个空的数据流和两个整数 <code>m</code> 和 <code>k</code> 初始化 <strong>MKAverage</strong> 对象。</li>
23-
<li><code>void addElement(int num)</code> 往数据流中插入一个新的元素 <code>num</code> 。</li>
24-
<li><code>int calculateMKAverage()</code> 对当前的数据流计算并返回 <strong>MK 平均数</strong> ,结果需 <strong>向下取整到最近的整数</strong> 。</li>
22+
<li><code>MKAverage(int m, int k)</code>&nbsp;用一个空的数据流和两个整数 <code>m</code>&nbsp;和 <code>k</code>&nbsp;初始化&nbsp;<strong>MKAverage</strong>&nbsp;对象。</li>
23+
<li><code>void addElement(int num)</code>&nbsp;往数据流中插入一个新的元素&nbsp;<code>num</code>&nbsp;。</li>
24+
<li><code>int calculateMKAverage()</code>&nbsp;对当前的数据流计算并返回 <strong>MK 平均数</strong>&nbsp;,结果需 <strong>向下取整到最近的整数</strong> 。</li>
2525
</ul>
2626

27-
<p> </p>
27+
<p>&nbsp;</p>
2828

2929
<p><strong>示例 1:</strong></p>
3030

@@ -42,25 +42,25 @@ obj.addElement(1); // 当前元素为 [3,1]
4242
obj.calculateMKAverage(); // 返回 -1 ,因为 m = 3 ,但数据流中只有 2 个元素
4343
obj.addElement(10); // 当前元素为 [3,1,10]
4444
obj.calculateMKAverage(); // 最后 3 个元素为 [3,1,10]
45-
// 删除最小以及最大的 1 个元素后,容器为 <code>[3]
45+
// 删除最小以及最大的 1 个元素后,容器为 [3]
4646
// [3] 的平均值等于 3/1 = 3 ,故返回 3
4747
obj.addElement(5); // 当前元素为 [3,1,10,5]
4848
obj.addElement(5); // 当前元素为 [3,1,10,5,5]
4949
obj.addElement(5); // 当前元素为 [3,1,10,5,5,5]
5050
obj.calculateMKAverage(); // 最后 3 个元素为 [5,5,5]
51-
// </code>删除最小以及最大的 1 个元素后,容器为 <code>[5]<code>
52-
// </code>[5] 的平均值等于 5/1 = 5 ,故返回 5<code>
53-
</code></code></pre>
51+
// 删除最小以及最大的 1 个元素后,容器为 [5]
52+
// [5] 的平均值等于 5/1 = 5 ,故返回 5
53+
</pre>
5454

55-
<p> </p>
55+
<p>&nbsp;</p>
5656

5757
<p><strong>提示:</strong></p>
5858

5959
<ul>
60-
<li><code>3 <= m <= 10<sup>5</sup></code></li>
61-
<li><code>1 <= k*2 < m</code></li>
62-
<li><code>1 <= num <= 10<sup>5</sup></code></li>
63-
<li><code>addElement</code> 与 <code>calculateMKAverage</code> 总操作次数不超过 <code>10<sup>5</sup></code> 次。</li>
60+
<li><code>3 &lt;= m &lt;= 10<sup>5</sup></code></li>
61+
<li><code>1 &lt;= k*2 &lt; m</code></li>
62+
<li><code>1 &lt;= num &lt;= 10<sup>5</sup></code></li>
63+
<li><code>addElement</code> 与&nbsp;<code>calculateMKAverage</code>&nbsp;总操作次数不超过 <code>10<sup>5</sup></code> 次。</li>
6464
</ul>
6565

6666
## 解法

solution/1800-1899/1825.Finding MK Average/README_EN.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@
3333
[null, null, null, -1, null, 3, null, null, null, 5]
3434

3535
<strong>Explanation</strong>
36-
MKAverage obj = new MKAverage(3, 1);
36+
<code>MKAverage obj = new MKAverage(3, 1);
3737
obj.addElement(3); // current elements are [3]
3838
obj.addElement(1); // current elements are [3,1]
3939
obj.calculateMKAverage(); // return -1, because m = 3 and only 2 elements exist.
4040
obj.addElement(10); // current elements are [3,1,10]
4141
obj.calculateMKAverage(); // The last 3 elements are [3,1,10].
42-
// After removing smallest and largest 1 element the container will be <code>[3].
42+
// After removing smallest and largest 1 element the container will be [3].
4343
// The average of [3] equals 3/1 = 3, return 3
4444
obj.addElement(5); // current elements are [3,1,10,5]
4545
obj.addElement(5); // current elements are [3,1,10,5,5]
4646
obj.addElement(5); // current elements are [3,1,10,5,5,5]
4747
obj.calculateMKAverage(); // The last 3 elements are [5,5,5].
48-
// After removing smallest and largest 1 element the container will be <code>[5].
48+
// After removing smallest and largest 1 element the container will be [5].
4949
// The average of [5] equals 5/1 = 5, return 5
50-
</code></code></pre>
50+
</code></pre>
5151

5252
<p>&nbsp;</p>
5353
<p><strong>Constraints:</strong></p>

solution/1800-1899/1828.Queries on Number of Points Inside a Circle/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public:
104104
for (auto& p : points) {
105105
int i = p[0], j = p[1];
106106
int dx = i - x, dy = j - y;
107-
cnt += dx * dx + dy * dy <= r * r;
107+
cnt += dx * dx + dy * dy <= r * r;
108108
}
109109
ans.emplace_back(cnt);
110110
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2539. Count the Number of Good Subsequences](https://leetcode.cn/problems/count-the-number-of-good-subsequences)
2+
3+
[English Version](/solution/2500-2599/2539.Count%20the%20Number%20of%20Good%20Subsequences/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>A <strong>subsequence</strong> of a string is&nbsp;good if it is not empty and the frequency of each one of its characters is the same.</p>
10+
11+
<p>Given a string <code>s</code>, return <em>the number of good subsequences of</em> <code>s</code>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
12+
13+
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> s = &quot;aabb&quot;
20+
<strong>Output:</strong> 11
21+
<strong>Explanation:</strong> The total number of subsequences is <code>2<sup>4</sup>. </code>There are five subsequences which are not good: &quot;<strong><u>aab</u></strong>b&quot;, &quot;a<u><strong>abb</strong></u>&quot;, &quot;<strong><u>a</u></strong>a<u><strong>bb</strong></u>&quot;, &quot;<u><strong>aa</strong></u>b<strong><u>b</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-5 = 11</code>.</pre>
22+
23+
<p><strong class="example">Example 2:</strong></p>
24+
25+
<pre>
26+
<strong>Input:</strong> s = &quot;leet&quot;
27+
<strong>Output:</strong> 12
28+
<strong>Explanation:</strong> There are four subsequences which are not good: &quot;<strong><u>l</u><em>ee</em></strong>t&quot;, &quot;l<u><strong>eet</strong></u>&quot;, &quot;<strong><u>leet</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-4 = 12</code>.
29+
</pre>
30+
31+
<p><strong class="example">Example 3:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> s = &quot;abcd&quot;
35+
<strong>Output:</strong> 15
36+
<strong>Explanation:</strong> All of the non-empty subsequences are good subsequences. Hence, the number of good subsequences is <code>2<sup>4</sup>-1 = 15</code>.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
44+
<li><code>s</code> consists of only lowercase English letters.</li>
45+
</ul>
46+
47+
## 解法
48+
49+
<!-- 这里可写通用的实现逻辑 -->
50+
51+
<!-- tabs:start -->
52+
53+
### **Python3**
54+
55+
<!-- 这里可写当前语言的特殊实现逻辑 -->
56+
57+
```python
58+
59+
```
60+
61+
### **Java**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```java
66+
67+
```
68+
69+
### **C++**
70+
71+
```cpp
72+
73+
```
74+
75+
### **Go**
76+
77+
```go
78+
79+
```
80+
81+
### **...**
82+
83+
```
84+
85+
```
86+
87+
<!-- tabs:end -->
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# [2539. Count the Number of Good Subsequences](https://leetcode.com/problems/count-the-number-of-good-subsequences)
2+
3+
[中文文档](/solution/2500-2599/2539.Count%20the%20Number%20of%20Good%20Subsequences/README.md)
4+
5+
## Description
6+
7+
<p>A <strong>subsequence</strong> of a string is&nbsp;good if it is not empty and the frequency of each one of its characters is the same.</p>
8+
9+
<p>Given a string <code>s</code>, return <em>the number of good subsequences of</em> <code>s</code>. Since the answer may be too large, return it modulo <code>10<sup>9</sup> + 7</code>.</p>
10+
11+
<p>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> s = &quot;aabb&quot;
18+
<strong>Output:</strong> 11
19+
<strong>Explanation:</strong> The total number of subsequences is <code>2<sup>4</sup>. </code>There are five subsequences which are not good: &quot;<strong><u>aab</u></strong>b&quot;, &quot;a<u><strong>abb</strong></u>&quot;, &quot;<strong><u>a</u></strong>a<u><strong>bb</strong></u>&quot;, &quot;<u><strong>aa</strong></u>b<strong><u>b</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-5 = 11</code>.</pre>
20+
21+
<p><strong class="example">Example 2:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> s = &quot;leet&quot;
25+
<strong>Output:</strong> 12
26+
<strong>Explanation:</strong> There are four subsequences which are not good: &quot;<strong><u>l</u><em>ee</em></strong>t&quot;, &quot;l<u><strong>eet</strong></u>&quot;, &quot;<strong><u>leet</u></strong>&quot;, and the empty subsequence. Hence, the number of good subsequences is <code>2<sup>4</sup>-4 = 12</code>.
27+
</pre>
28+
29+
<p><strong class="example">Example 3:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> s = &quot;abcd&quot;
33+
<strong>Output:</strong> 15
34+
<strong>Explanation:</strong> All of the non-empty subsequences are good subsequences. Hence, the number of good subsequences is <code>2<sup>4</sup>-1 = 15</code>.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= s.length &lt;= 10<sup>4</sup></code></li>
42+
<li><code>s</code> consists of only lowercase English letters.</li>
43+
</ul>
44+
45+
## Solutions
46+
47+
<!-- tabs:start -->
48+
49+
### **Python3**
50+
51+
```python
52+
53+
```
54+
55+
### **Java**
56+
57+
```java
58+
59+
```
60+
61+
### **C++**
62+
63+
```cpp
64+
65+
```
66+
67+
### **Go**
68+
69+
```go
70+
71+
```
72+
73+
### **...**
74+
75+
```
76+
77+
```
78+
79+
<!-- tabs:end -->

solution/CONTEST_README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
| 段位 | 比例 | 段位名 | 国服分数线 | 勋章 |
1313
| ----- | ------ | -------- | --------- | --------------------------------------------------------------------------- |
14-
| LV3 | 5% | Guardian | &ge;2247.09 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
15-
| LV2 | 20% | Knight | &ge;1881.35 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
14+
| LV3 | 5% | Guardian | &ge;2249.79 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
15+
| LV2 | 20% | Knight | &ge;1882.71 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
1616
| LV1 | 75% | - | - | - |
1717

1818
力扣竞赛 **全国排名前 10** 的用户,全站用户名展示为品牌橙色。

solution/CONTEST_README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ If you are in the top 25% of the contest rating, you’ll get the “Knight” b
1313

1414
| Level | Proportion | Badge | Rating | |
1515
| ----- | ---------- | ---------- | -------------- | ----------------------------------------------------------------------------------------------------------------------- |
16-
| LV3 | 5\% | Guardian | &ge;2389.82 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
16+
| LV3 | 5\% | Guardian | &ge;2228.90 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
1717
| LV2 | 20\% | Knight | &ge;1842.73 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
1818
| LV1 | 75\% | - | - | - |
1919

0 commit comments

Comments
 (0)