Skip to content

Commit 2753b23

Browse files
author
Shuo
authored
Merge pull request #782 from openset/develop
A: v1.6.0
2 parents ddf74e1 + 9c963b5 commit 2753b23

File tree

18 files changed

+426
-235
lines changed

18 files changed

+426
-235
lines changed

Diff for: internal/leetcode/topic_tag.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ func (tag *TagType) SaveContents() {
3838
buf.WriteString("| # | 题目 | 标签 | 难度 |\n")
3939
buf.WriteString("| :-: | - | - | :-: |\n")
4040
format := "| %d | [%s](../../problems/%s)%s | %s | %s |\n"
41+
preID := 0
4142
for _, question := range questions {
4243
if question.TranslatedTitle == "" {
4344
question.TranslatedTitle = question.Title
4445
}
45-
if question.frontendID() > 0 {
46+
if question.frontendID() > 0 && question.frontendID() != preID {
47+
preID = question.frontendID()
4648
buf.WriteString(fmt.Sprintf(format, question.frontendID(), question.TranslatedTitle, question.TitleSlug, question.IsPaidOnly.Str(), question.TagsStr(), question.Difficulty))
4749
}
4850
}

Diff for: internal/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/openset/leetcode/internal/base"
99
)
1010

11-
const version = "1.5.3"
11+
const version = "1.6.0"
1212

1313
// CmdVersion - version.CmdVersion
1414
var CmdVersion = &base.Command{

Diff for: problems/backspace-string-compare/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<p>Given two&nbsp;strings&nbsp;<code>S</code>&nbsp;and <code>T</code>,&nbsp;return if they are equal when both are typed into empty text editors. <code>#</code> means a backspace character.</p>
1515

16+
<p>Note that after&nbsp;backspacing an empty text, the text will continue empty.</p>
17+
1618
<div>
1719
<p><strong>Example 1:</strong></p>
1820

@@ -51,11 +53,11 @@
5153

5254
<p><span><strong>Note</strong>:</span></p>
5355

54-
<ol>
56+
<ul>
5557
<li><code><span>1 &lt;= S.length &lt;= 200</span></code></li>
5658
<li><code><span>1 &lt;= T.length &lt;= 200</span></code></li>
5759
<li><span><code>S</code>&nbsp;and <code>T</code> only contain&nbsp;lowercase letters and <code>&#39;#&#39;</code> characters.</span></li>
58-
</ol>
60+
</ul>
5961

6062
<p><strong>Follow up:</strong></p>
6163

Diff for: problems/capital-gainloss/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,56 @@
1111

1212
## [1393. Capital Gain/Loss (Medium)](https://leetcode.com/problems/capital-gainloss "股票的资本损益")
1313

14+
<p>Table: <code>Stocks</code></p>
15+
<pre>
16+
+---------------+---------+
17+
| Column Name | Type |
18+
+---------------+---------+
19+
| stock_name | varchar |
20+
| operation | enum |
21+
| operation_day | int |
22+
| price | int |
23+
+---------------+---------+
24+
(stock_name, day) is the primary key for this table.
25+
The operation column is an ENUM of type ('Sell', 'Buy')
26+
Each row of this table indicates that the stock which has stock_name had an operation on the day operation_day with the price.
27+
It is guaranteed that each 'Sell' operation for a stock has a corresponding 'Buy' operation in a previous day.
28+
</pre>
29+
30+
Write an SQL query to report the Capital gain/loss for each stock.
1431

32+
The capital gain/loss of a stock is total gain or loss after buying and selling the stock one or many times.
33+
34+
Return the result table in any order.
35+
36+
The query result format is in the following example:
37+
38+
<pre>
39+
Stocks table:
40+
+---------------+-----------+---------------+--------+
41+
| stock_name | operation | operation_day | price |
42+
+---------------+-----------+---------------+--------+
43+
| Leetcode | Buy | 1 | 1000 |
44+
| Corona Masks | Buy | 2 | 10 |
45+
| Leetcode | Sell | 5 | 9000 |
46+
| Handbags | Buy | 17 | 30000 |
47+
| Corona Masks | Sell | 3 | 1010 |
48+
| Corona Masks | Buy | 4 | 1000 |
49+
| Corona Masks | Sell | 5 | 500 |
50+
| Corona Masks | Buy | 6 | 1000 |
51+
| Handbags | Sell | 29 | 7000 |
52+
| Corona Masks | Sell | 10 | 10000 |
53+
+---------------+-----------+---------------+--------+
54+
55+
Result table:
56+
+---------------+-------------------+
57+
| stock_name | capital_gain_loss |
58+
+---------------+-------------------+
59+
| Corona Masks | 9500 |
60+
| Leetcode | 8000 |
61+
| Handbags | -23000 |
62+
+---------------+-------------------+
63+
Leetcode stock was bought at day 1 for 1000$ and was sold at day 5 for 9000$. Capital gain = 9000 - 1000 = 8000$.
64+
Handbags stock was bought at day 17 for 30000$ and was sold at day 29 for 7000$. Capital loss = 7000 - 30000 = -23000$.
65+
Corona Masks stock was bought at day 1 for 10$ and was sold at day 3 for 1010$. It was bought again at day 4 for 1000$ and was sold at day 5 for 500$. At last, it was bought at day 6 for 1000$ and was sold at day 10 for 10000$. Capital gain/loss is the sum of capital gains/losses for each ('Buy' --> 'Sell') operation = (1010 - 10) + (500 - 1000) + (10000 - 1000) = 1000 - 500 + 9000 = 9500$.
66+
</pre>

Diff for: problems/customers-who-bought-products-a-and-b-but-not-c/README.md

+64
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,68 @@
1111

1212
## [1398. Customers Who Bought Products A and B but Not C (Medium)](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c "购买了产品A和产品B却没有购买产品C的顾客")
1313

14+
<p>Table: <code>Customers</code></p>
15+
<pre>
16+
+---------------------+---------+
17+
| Column Name | Type |
18+
+---------------------+---------+
19+
| customer_id | int |
20+
| customer_name | varchar |
21+
+---------------------+---------+
22+
customer_id is the primary key for this table.
23+
customer_name is the name of the customer.
24+
</pre>
25+
26+
<p>Table: <code>Orders</code></p>
27+
<pre>
28+
+---------------+---------+
29+
| Column Name | Type |
30+
+---------------+---------+
31+
| order_id | int |
32+
| customer_id | int |
33+
| product_name | varchar |
34+
+---------------+---------+
35+
order_id is the primary key for this table.
36+
customer_id is the id of the customer who bought the product "product_name".
37+
</pre>
38+
39+
Write an SQL query to report the customer_id and customer_name of customers who bought products "A", "B" but did not buy the product "C" since we want to recommend them buy this product.
1440

41+
Return the result table ordered by customer_id.
42+
43+
The query result format is in the following example.
44+
45+
<pre>
46+
Customers table:
47+
+-------------+---------------+
48+
| customer_id | customer_name |
49+
+-------------+---------------+
50+
| 1 | Daniel |
51+
| 2 | Diana |
52+
| 3 | Elizabeth |
53+
| 4 | Jhon |
54+
+-------------+---------------+
55+
56+
Orders table:
57+
+------------+--------------+---------------+
58+
| order_id | customer_id | product_name |
59+
+------------+--------------+---------------+
60+
| 10 | 1 | A |
61+
| 20 | 1 | B |
62+
| 30 | 1 | D |
63+
| 40 | 1 | C |
64+
| 50 | 2 | A |
65+
| 60 | 3 | A |
66+
| 70 | 3 | B |
67+
| 80 | 3 | D |
68+
| 90 | 4 | C |
69+
+------------+--------------+---------------+
70+
71+
Result table:
72+
+-------------+---------------+
73+
| customer_id | customer_name |
74+
+-------------+---------------+
75+
| 3 | Elizabeth |
76+
+-------------+---------------+
77+
Only the customer_id with id 3 bought the product A and B but not the product C.
78+
</pre>

Diff for: problems/delete-columns-to-make-sorted/README.md

+10-18
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,46 @@
1515

1616
<p>Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.</p>
1717

18-
<p>For example, if we have an array <code>A = [&quot;</code><code>abcdef</code><code>&quot;,&quot;uvwxyz&quot;]</code> and deletion indices <code>{0, 2, 3}</code>, then the final array after deletions is <code>[&quot;bef&quot;, &quot;vyz&quot;]</code>,&nbsp;and the remaining columns of <code>A</code> are&nbsp;<code>[&quot;b&quot;</code><code>,&quot;</code><code>v&quot;]</code>, <code>[&quot;e&quot;,&quot;y&quot;]</code>, and <code>[&quot;f&quot;,&quot;z&quot;]</code>.&nbsp; (Formally, the <code>c</code>-th column is <code>[A[0][c], A[1][c], ..., A[A.length-1][c]]</code>.)</p>
18+
<p>For example, if we have an array <code>A = [&quot;abcdef&quot;,&quot;uvwxyz&quot;]</code> and deletion indices <code>{0, 2, 3}</code>, then the final array after deletions is <code>[&quot;bef&quot;, &quot;vyz&quot;]</code>,&nbsp;and the remaining columns of <code>A</code> are&nbsp;<code>[&quot;b&quot;,&quot;v&quot;]</code>, <code>[&quot;e&quot;,&quot;y&quot;]</code>, and <code>[&quot;f&quot;,&quot;z&quot;]</code>.&nbsp; (Formally, the <code>c</code>-th column is <code>[A[0][c], A[1][c], ..., A[A.length-1][c]]</code>).</p>
1919

2020
<p>Suppose we chose a set of deletion indices <code>D</code> such that after deletions, each remaining column in A is in <strong>non-decreasing</strong> sorted order.</p>
2121

2222
<p>Return the minimum possible value of <code>D.length</code>.</p>
2323

2424
<p>&nbsp;</p>
25-
26-
<div>
2725
<p><strong>Example 1:</strong></p>
2826

2927
<pre>
30-
<strong>Input: </strong><span id="example-input-1-1">[&quot;cba&quot;,&quot;daf&quot;,&quot;ghi&quot;]</span>
31-
<strong>Output: </strong><span id="example-output-1">1</span>
28+
<strong>Input:</strong> A = [&quot;cba&quot;,&quot;daf&quot;,&quot;ghi&quot;]
29+
<strong>Output:</strong> 1
3230
<strong>Explanation: </strong>
3331
After choosing D = {1}, each column [&quot;c&quot;,&quot;d&quot;,&quot;g&quot;] and [&quot;a&quot;,&quot;f&quot;,&quot;i&quot;] are in non-decreasing sorted order.
3432
If we chose D = {}, then a column [&quot;b&quot;,&quot;a&quot;,&quot;h&quot;] would not be in non-decreasing sorted order.
3533
</pre>
3634

37-
<div>
3835
<p><strong>Example 2:</strong></p>
3936

4037
<pre>
41-
<strong>Input: </strong><span id="example-input-2-1">[&quot;a&quot;,&quot;b&quot;]</span>
42-
<strong>Output: </strong><span id="example-output-2">0</span>
38+
<strong>Input:</strong> A = [&quot;a&quot;,&quot;b&quot;]
39+
<strong>Output:</strong> 0
4340
<strong>Explanation: </strong>D = {}
4441
</pre>
4542

46-
<div>
4743
<p><strong>Example 3:</strong></p>
4844

4945
<pre>
50-
<strong>Input: </strong><span id="example-input-3-1">[&quot;zyx&quot;,&quot;wvu&quot;,&quot;tsr&quot;]</span>
51-
<strong>Output: </strong><span id="example-output-3">3</span>
46+
<strong>Input:</strong> A = [&quot;zyx&quot;,&quot;wvu&quot;,&quot;tsr&quot;]
47+
<strong>Output:</strong> 3
5248
<strong>Explanation: </strong>D = {0, 1, 2}
5349
</pre>
5450

5551
<p>&nbsp;</p>
52+
<p><strong>Constraints:</strong></p>
5653

57-
<p><strong><span>Note:</span></strong></p>
58-
59-
<ol>
54+
<ul>
6055
<li><code>1 &lt;= A.length &lt;= 100</code></li>
6156
<li><code>1 &lt;= A[i].length &lt;= 1000</code></li>
62-
</ol>
63-
</div>
64-
</div>
65-
</div>
57+
</ul>
6658

6759
### Related Topics
6860
[[Greedy](../../tag/greedy/README.md)]

Diff for: problems/distinct-subsequences/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515

1616
<p>A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, <code>&quot;ACE&quot;</code> is a subsequence of <code>&quot;ABCDE&quot;</code> while <code>&quot;AEC&quot;</code> is not).</p>
1717

18+
<p>It&#39;s guaranteed the answer fits on a 32-bit signed integer.</p>
19+
1820
<p><strong>Example 1:</strong></p>
1921

2022
<pre>
2123
<strong>Input: </strong>S = <code>&quot;rabbbit&quot;</code>, T = <code>&quot;rabbit&quot;
2224
<strong>Output:</strong>&nbsp;3
23-
</code><strong>Explanation:
24-
</strong>
25+
</code><strong>Explanation:</strong>
2526
As shown below, there are 3 ways you can generate &quot;rabbit&quot; from S.
2627
(The caret symbol ^ means the chosen letters)
2728

@@ -38,8 +39,7 @@ As shown below, there are 3 ways you can generate &quot;rabbit&quot; from S.
3839
<pre>
3940
<strong>Input: </strong>S = <code>&quot;babgbag&quot;</code>, T = <code>&quot;bag&quot;
4041
<strong>Output:</strong>&nbsp;5
41-
</code><strong>Explanation:
42-
</strong>
42+
</code><strong>Explanation:</strong>
4343
As shown below, there are 5 ways you can generate &quot;bag&quot; from S.
4444
(The caret symbol ^ means the chosen letters)
4545

Diff for: problems/get-the-second-most-recent-activity/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,48 @@
1111

1212
## [1369. Get the Second Most Recent Activity (Hard)](https://leetcode.com/problems/get-the-second-most-recent-activity "获取最近第二次的活动")
1313

14+
SQL Schema
15+
<p>Table: <code>UserActivity</code></p>
16+
<pre>
17+
+---------------+---------+
18+
| Column Name | Type |
19+
+---------------+---------+
20+
| username | varchar |
21+
| activity | varchar |
22+
| startDate | Date |
23+
| endDate | Date |
24+
+---------------+---------+
25+
This table does not contain primary key.
26+
This table contain information about the activity performed of each user in a period of time.
27+
A person with username performed a activity from startDate to endDate.
28+
</pre>
1429

30+
Write an SQL query to show the second most recent activity of each user.
31+
32+
If the user only has one activity, return that one.
33+
34+
A user can't perform more than one activity at the same time. Return the result table in any order.
35+
36+
The query result format is in the following example:
37+
<pre>
38+
UserActivity table:
39+
+------------+--------------+-------------+-------------+
40+
| username | activity | startDate | endDate |
41+
+------------+--------------+-------------+-------------+
42+
| Alice | Travel | 2020-02-12 | 2020-02-20 |
43+
| Alice | Dancing | 2020-02-21 | 2020-02-23 |
44+
| Alice | Travel | 2020-02-24 | 2020-02-28 |
45+
| Bob | Travel | 2020-02-11 | 2020-02-18 |
46+
+------------+--------------+-------------+-------------+
47+
48+
Result table:
49+
+------------+--------------+-------------+-------------+
50+
| username | activity | startDate | endDate |
51+
+------------+--------------+-------------+-------------+
52+
| Alice | Dancing | 2020-02-21 | 2020-02-23 |
53+
| Bob | Travel | 2020-02-11 | 2020-02-18 |
54+
+------------+--------------+-------------+-------------+
55+
56+
The most recent activity of Alice is Travel from 2020-02-24 to 2020-02-28, before that she was dancing from 2020-02-21 to 2020-02-23.
57+
Bob only has one record, we just take that one.
58+
</pre>

Diff for: problems/longest-uncommon-subsequence-i/README.md

+34-22
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,45 @@
1111

1212
## [521. Longest Uncommon Subsequence I (Easy)](https://leetcode.com/problems/longest-uncommon-subsequence-i "最长特殊序列 Ⅰ")
1313

14-
<p>
15-
Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings.
16-
The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be <b>any</b> subsequence of the other strings.
17-
</p>
14+
<p>Given two strings, you need to find the longest uncommon subsequence&nbsp;of this two strings. The longest uncommon subsequence is defined as the longest subsequence of one of these strings and this subsequence should not be <b>any</b> subsequence of the other string.</p>
1815

19-
<p>
20-
A <b>subsequence</b> is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.
21-
</p>
16+
<p>A <b>subsequence</b> is a sequence that can be derived from one sequence by deleting some characters without changing the order of the remaining elements. Trivially, any string is a subsequence of itself and an empty string is a subsequence of any string.</p>
2217

23-
<p>
24-
The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn't exist, return -1.
25-
</p>
18+
<p>The input will be two strings, and the output needs to be the length of the longest uncommon subsequence. If the longest uncommon subsequence doesn&#39;t exist, return -1.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> a = &quot;aba&quot;, b = &quot;cdc&quot;
25+
<strong>Output:</strong> 3
26+
<strong>Explanation:</strong> The longest uncommon subsequence is &quot;aba&quot;,
27+
because &quot;aba&quot; is a subsequence of &quot;aba&quot;,
28+
but not a subsequence of the other string &quot;cdc&quot;.
29+
Note that &quot;cdc&quot; can be also a longest uncommon subsequence.
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
2633

27-
<p><b>Example 1:</b><br />
2834
<pre>
29-
<b>Input:</b> "aba", "cdc"
30-
<b>Output:</b> 3
31-
<b>Explanation:</b> The longest uncommon subsequence is "aba" (or "cdc"), <br/>because "aba" is a subsequence of "aba", <br/>but not a subsequence of any other strings in the group of two strings.
35+
<strong>Input:</strong> a = &quot;aaa&quot;, b = &quot;bbb&quot;
36+
<strong>Output:</strong> 3
3237
</pre>
33-
</p>
34-
35-
<p><b>Note:</b>
36-
<ol>
37-
<li>Both strings' lengths will not exceed 100.</li>
38-
<li>Only letters from a ~ z will appear in input strings. </li>
39-
</ol>
40-
</p>
38+
39+
<p><strong>Example 3:</strong></p>
40+
41+
<pre>
42+
<strong>Input:</strong> a = &quot;aaa&quot;, b = &quot;aaa&quot;
43+
<strong>Output:</strong> -1
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li>Both strings&#39; lengths will be between <code>[1 - 100]</code>.</li>
51+
<li>Only letters from a ~ z will appear in input strings.</li>
52+
</ul>
4153

4254
### Related Topics
4355
[[String](../../tag/string/README.md)]

0 commit comments

Comments
 (0)