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 e4250e6

Browse files
author
Shuo
authored
Merge pull request #813 from openset/develop
A: new
2 parents 4e6383b + 19f56f6 commit e4250e6

File tree

55 files changed

+1068
-385
lines changed

Some content is hidden

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

55 files changed

+1068
-385
lines changed

‎README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ LeetCode Problems' Solutions
7070

7171
| # | Title | Solution | Difficulty |
7272
| :-: | - | - | :-: |
73+
| <span id="1585">1585</span> | [Check If String Is Transformable With Substring Sort Operations](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations "检查字符串是否可以通过排序子字符串得到另一个字符串") | [Go](problems/check-if-string-is-transformable-with-substring-sort-operations) | Hard |
74+
| <span id="1584">1584</span> | [Min Cost to Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points "连接所有点的最小费用") | [Go](problems/min-cost-to-connect-all-points) | Medium |
75+
| <span id="1583">1583</span> | [Count Unhappy Friends](https://leetcode.com/problems/count-unhappy-friends "统计不开心的朋友") | [Go](problems/count-unhappy-friends) | Medium |
76+
| <span id="1582">1582</span> | [Special Positions in a Binary Matrix](https://leetcode.com/problems/special-positions-in-a-binary-matrix "二进制矩阵中的特殊位置") | [Go](problems/special-positions-in-a-binary-matrix) | Easy |
77+
| <span id="1581">1581</span> | [Customer Who Visited but Did Not Make Any Transactions](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions) 🔒 | [MySQL](problems/customer-who-visited-but-did-not-make-any-transactions) | Easy |
78+
| <span id="1580">1580</span> | [Put Boxes Into the Warehouse II](https://leetcode.com/problems/put-boxes-into-the-warehouse-ii) 🔒 | [Go](problems/put-boxes-into-the-warehouse-ii) | Medium |
7379
| <span id="1579">1579</span> | [Remove Max Number of Edges to Keep Graph Fully Traversable](https://leetcode.com/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable "保证图可完全遍历") | [Go](problems/remove-max-number-of-edges-to-keep-graph-fully-traversable) | Hard |
7480
| <span id="1578">1578</span> | [Minimum Deletion Cost to Avoid Repeating Letters](https://leetcode.com/problems/minimum-deletion-cost-to-avoid-repeating-letters "避免重复字母的最小删除成本") | [Go](problems/minimum-deletion-cost-to-avoid-repeating-letters) | Medium |
7581
| <span id="1577">1577</span> | [Number of Ways Where Square of Number Is Equal to Product of Two Numbers](https://leetcode.com/problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers "数的平方等于两数乘积的方法数") | [Go](problems/number-of-ways-where-square-of-number-is-equal-to-product-of-two-numbers) | Medium |
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../min-cost-to-connect-all-points "Min Cost to Connect All Points")
9+
10+
Next >
11+
12+
## [1585. Check If String Is Transformable With Substring Sort Operations (Hard)](https://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations "检查字符串是否可以通过排序子字符串得到另一个字符串")
13+
14+
<p>Given two strings&nbsp;<code>s</code> and <code>t</code>, you want to transform string&nbsp;<code>s</code> into string&nbsp;<code>t</code> using the following&nbsp;operation any number of times:</p>
15+
16+
<ul>
17+
<li>Choose a <strong>non-empty</strong> substring in&nbsp;<code>s</code>&nbsp;and sort it in-place&nbsp;so the characters are in&nbsp;<strong>ascending order</strong>.</li>
18+
</ul>
19+
20+
<p>For example, applying the operation on the underlined substring in&nbsp;<code>&quot;1<u>4234</u>&quot;</code>&nbsp;results in <code>&quot;1<u>2344</u>&quot;</code>.</p>
21+
22+
<p>Return <code>true</code> if <em>it is possible to transform string <code>s</code>&nbsp;into string <code>t</code></em>. Otherwise,&nbsp;return <code>false</code>.</p>
23+
24+
<p>A <strong>substring</strong>&nbsp;is a contiguous sequence of characters within a string.</p>
25+
26+
<p>&nbsp;</p>
27+
<p><strong>Example 1:</strong></p>
28+
29+
<pre>
30+
<strong>Input:</strong> s = &quot;84532&quot;, t = &quot;34852&quot;
31+
<strong>Output:</strong> true
32+
<strong>Explanation:</strong> You can transform s into t using the following sort operations:
33+
&quot;84<u>53</u>2&quot; (from index 2 to 3) -&gt; &quot;84<u>35</u>2&quot;
34+
&quot;<u>843</u>52&quot; (from index 0 to 2) -&gt; &quot;<u>348</u>52&quot;
35+
</pre>
36+
37+
<p><strong>Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> s = &quot;34521&quot;, t = &quot;23415&quot;
41+
<strong>Output:</strong> true
42+
<strong>Explanation:</strong> You can transform s into t using the following sort operations:
43+
&quot;<u>3452</u>1&quot; -&gt; &quot;<u>2345</u>1&quot;
44+
&quot;234<u>51</u>&quot; -&gt; &quot;234<u>15</u>&quot;
45+
</pre>
46+
47+
<p><strong>Example 3:</strong></p>
48+
49+
<pre>
50+
<strong>Input:</strong> s = &quot;12345&quot;, t = &quot;12435&quot;
51+
<strong>Output:</strong> false
52+
</pre>
53+
54+
<p><strong>Example 4:</strong></p>
55+
56+
<pre>
57+
<strong>Input:</strong> s = &quot;1&quot;, t = &quot;2&quot;
58+
<strong>Output:</strong> false
59+
</pre>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Constraints:</strong></p>
63+
64+
<ul>
65+
<li><code>s.length == t.length</code></li>
66+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
67+
<li><code>s</code> and <code>t</code>&nbsp;only contain digits from <code>&#39;0&#39;</code> to <code>&#39;9&#39;</code>.</li>
68+
</ul>
69+
70+
### Related Topics
71+
[[Greedy](../../tag/greedy/README.md)]
72+
[[String](../../tag/string/README.md)]
73+
74+
### Hints
75+
<details>
76+
<summary>Hint 1</summary>
77+
Suppose the first digit you need is 'd'. How can you determine if it's possible to get that digit there?
78+
</details>
79+
80+
<details>
81+
<summary>Hint 2</summary>
82+
Consider swapping adjacent characters to maintain relative ordering.
83+
</details>

‎problems/compare-version-numbers/README.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,71 @@
1111

1212
## [165. Compare Version Numbers (Medium)](https://leetcode.com/problems/compare-version-numbers "比较版本号")
1313

14-
<p>Compare two version numbers <em>version1</em> and <em>version2</em>.<br />
15-
If <code><em>version1</em> &gt; <em>version2</em></code> return <code>1;</code>&nbsp;if <code><em>version1</em> &lt; <em>version2</em></code> return <code>-1;</code>otherwise return <code>0</code>.</p>
14+
<p>Given two version numbers,&nbsp;<code>version1</code> and <code>version2</code>, compare them.</p>
1615

17-
<p>You may assume that the version strings are non-empty and contain only digits and the <code>.</code> character.</p>
18-
<p>The <code>.</code> character does not represent a decimal point and is used to separate number sequences.</p>
19-
<p>For instance, <code>2.5</code> is not &quot;two and a half&quot; or &quot;half way to version three&quot;, it is the fifth second-level revision of the second first-level revision.</p>
20-
<p>You may assume the default revision number for each level of a version number to be <code>0</code>. For example, version number <code>3.4</code> has a revision number of <code>3</code> and <code>4</code> for its first and second level revision number. Its third and fourth level revision number are both <code>0</code>.</p>
16+
<ul>
17+
</ul>
2118

22-
<p>&nbsp;</p>
19+
<p>Version numbers consist of <strong>one or more revisions</strong> joined by a dot&nbsp;<code>&#39;.&#39;</code>. Each revision&nbsp;consists of <strong>digits</strong>&nbsp;and may contain leading <strong>zeros</strong>. Every revision contains <strong>at least one character</strong>. Revisions are <strong>0-indexed from left to right</strong>, with the leftmost revision being revision 0, the next revision being revision 1, and so on. For example&nbsp;<code>2.5.33</code>&nbsp;and&nbsp;<code>0.1</code>&nbsp;are valid version numbers.</p>
20+
21+
<p>To compare version numbers, compare their revisions in <strong>left-to-right order</strong>. Revisions are compared using their&nbsp;<strong>integer value ignoring any leading zeros</strong>. This means that revisions&nbsp;<code>1</code>&nbsp;and&nbsp;<code>001</code>&nbsp;are considered&nbsp;<strong>equal</strong>. If a version number does not specify a revision at an index, then&nbsp;<strong>treat the revision as&nbsp;<code>0</code></strong>. For example, version&nbsp;<code>1.0</code> is less than version&nbsp;<code>1.1</code>&nbsp;because their revision 0s are the same, but their revision 1s are&nbsp;<code>0</code>&nbsp;and&nbsp;<code>1</code>&nbsp;respectively, and&nbsp;<code>0 &lt; 1</code>.</p>
22+
23+
<p><em>Return the following:</em></p>
24+
25+
<ul>
26+
<li>If <code>version1 &lt; version2</code>, return <code>-1</code>.</li>
27+
<li>If <code>version1 &gt; version2</code>, return <code>1</code>.</li>
28+
<li>Otherwise, return <code>0</code>.</li>
29+
</ul>
2330

31+
<p>&nbsp;</p>
2432
<p><strong>Example 1:</strong></p>
33+
2534
<pre>
26-
<strong>Input:</strong> <code><em>version1</em></code> = &quot;0.1&quot;, <code><em>version2</em></code> = &quot;1.1&quot;
27-
<strong>Output:</strong> -1</pre>
35+
<strong>Input:</strong> version1 = &quot;1.01&quot;, version2 = &quot;1.001&quot;
36+
<strong>Output:</strong> 0
37+
<strong>Explanation:</strong> Ignoring leading zeroes, both &quot;01&quot; and &quot;001&quot; represent the same integer &quot;1&quot;.
38+
</pre>
2839

2940
<p><strong>Example 2:</strong></p>
41+
3042
<pre>
31-
<strong>Input: </strong><code><em>version1</em></code> = &quot;1.0.1&quot;, <code><em>version2</em></code> = &quot;1&quot;
32-
<strong>Output:</strong> 1</pre>
43+
<strong>Input:</strong> version1 = &quot;1.0&quot;, version2 = &quot;1.0.0&quot;
44+
<strong>Output:</strong> 0
45+
<strong>Explanation:</strong> version1 does not specify revision 2, which means it is treated as &quot;0&quot;.
46+
</pre>
3347

3448
<p><strong>Example 3:</strong></p>
49+
3550
<pre>
36-
<strong>Input:</strong> <code><em>version1</em></code> = &quot;7.5.2.4&quot;, <code><em>version2</em></code> = &quot;7.5.3&quot;
37-
<strong>Output:</strong> -1</pre>
51+
<strong>Input:</strong> version1 = &quot;0.1&quot;, version2 = &quot;1.1&quot;
52+
<strong>Output:</strong> -1
53+
<strong>Explanation:</strong>&nbsp;version1&#39;s revision 0 is &quot;0&quot;, while version2&#39;s revision 0 is &quot;1&quot;. 0 &lt; 1, so version1 &lt; version2.
54+
</pre>
3855

3956
<p><strong>Example 4:</strong></p>
57+
4058
<pre>
41-
<strong>Input:</strong> <code><em>version1</em></code> = &quot;1.01&quot;, <code><em>version2</em></code> = &quot;1.001&quot;
42-
<strong>Output:</strong> 0
43-
<strong>Explanation:</strong> Ignoring leading zeroes, both "01" and "001" represent the same number "1"</pre>
59+
<strong>Input:</strong> version1 = &quot;1.0.1&quot;, version2 = &quot;1&quot;
60+
<strong>Output:</strong> 1
61+
</pre>
4462

4563
<p><strong>Example 5:</strong></p>
64+
4665
<pre>
47-
<strong>Input:</strong> <code><em>version1</em></code> = &quot;1.0&quot;, <code><em>version2</em></code> = &quot;1.0.0&quot;
48-
<strong>Output:</strong> 0
49-
<strong>Explanation:</strong> The first version number does not have a third level revision number, which means its third level revision number is default to "0"</pre>
66+
<strong>Input:</strong> version1 = &quot;7.5.2.4&quot;, version2 = &quot;7.5.3&quot;
67+
<strong>Output:</strong> -1
68+
</pre>
5069

5170
<p>&nbsp;</p>
71+
<p><strong>Constraints:</strong></p>
5272

53-
<p><strong>Note:</strong></p>
54-
<ol>
55-
<li>Version strings are composed of numeric strings separated by dots <code>.</code> and this numeric strings <strong>may</strong> have leading zeroes. </li>
56-
<li>Version strings do not start or end with dots, and they will not be two consecutive dots.</li>
57-
</ol>
73+
<ul>
74+
<li><code>1 &lt;= version1.length, version2.length &lt;= 500</code></li>
75+
<li><code>version1</code> and <code>version2</code>&nbsp;only contain digits and <code>&#39;.&#39;</code>.</li>
76+
<li><code>version1</code> and <code>version2</code>&nbsp;<strong>are valid version numbers</strong>.</li>
77+
<li>All the given revisions in&nbsp;<code>version1</code> and <code>version2</code>&nbsp;can be stored in&nbsp;a&nbsp;<strong>32-bit integer</strong>.</li>
78+
</ul>
5879

5980
### Related Topics
6081
[[String](../../tag/string/README.md)]

‎problems/count-and-say/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
### Similar Questions
5454
1. [Encode and Decode Strings](../encode-and-decode-strings) (Medium)
55-
1. [String Compression](../string-compression) (Easy)
55+
1. [String Compression](../string-compression) (Medium)
5656

5757
### Hints
5858
<details>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../special-positions-in-a-binary-matrix "Special Positions in a Binary Matrix")
9+
10+
[Next >](../min-cost-to-connect-all-points "Min Cost to Connect All Points")
11+
12+
## [1583. Count Unhappy Friends (Medium)](https://leetcode.com/problems/count-unhappy-friends "统计不开心的朋友")
13+
14+
<p>You are given a list of&nbsp;<code>preferences</code>&nbsp;for&nbsp;<code>n</code>&nbsp;friends, where <code>n</code> is always <strong>even</strong>.</p>
15+
16+
<p>For each person <code>i</code>,&nbsp;<code>preferences[i]</code>&nbsp;contains&nbsp;a list of friends&nbsp;<strong>sorted</strong> in the <strong>order of preference</strong>. In other words, a friend earlier in the list is more preferred than a friend later in the list.&nbsp;Friends in&nbsp;each list are&nbsp;denoted by integers from <code>0</code> to <code>n-1</code>.</p>
17+
18+
<p>All the friends are divided into pairs.&nbsp;The pairings are&nbsp;given in a list&nbsp;<code>pairs</code>,&nbsp;where <code>pairs[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> denotes <code>x<sub>i</sub></code>&nbsp;is paired with <code>y<sub>i</sub></code> and <code>y<sub>i</sub></code> is paired with <code>x<sub>i</sub></code>.</p>
19+
20+
<p>However, this pairing may cause some of the friends to be unhappy.&nbsp;A friend <code>x</code>&nbsp;is unhappy if <code>x</code>&nbsp;is paired with <code>y</code>&nbsp;and there exists a friend <code>u</code>&nbsp;who&nbsp;is paired with <code>v</code>&nbsp;but:</p>
21+
22+
<ul>
23+
<li><code>x</code>&nbsp;prefers <code>u</code>&nbsp;over <code>y</code>,&nbsp;and</li>
24+
<li><code>u</code>&nbsp;prefers <code>x</code>&nbsp;over <code>v</code>.</li>
25+
</ul>
26+
27+
<p>Return <em>the number of unhappy friends</em>.</p>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input:</strong> n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]
34+
<strong>Output:</strong> 2
35+
<strong>Explanation:</strong>
36+
Friend 1 is unhappy because:
37+
- 1 is paired with 0 but prefers 3 over 0, and
38+
- 3 prefers 1 over 2.
39+
Friend 3 is unhappy because:
40+
- 3 is paired with 2 but prefers 1 over 2, and
41+
- 1 prefers 3 over 0.
42+
Friends 0 and 2 are happy.
43+
</pre>
44+
45+
<p><strong>Example 2:</strong></p>
46+
47+
<pre>
48+
<strong>Input:</strong> n = 2, preferences = [[1], [0]], pairs = [[1, 0]]
49+
<strong>Output:</strong> 0
50+
<strong>Explanation:</strong> Both friends 0 and 1 are happy.
51+
</pre>
52+
53+
<p><strong>Example 3:</strong></p>
54+
55+
<pre>
56+
<strong>Input:</strong> n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, 1]], pairs = [[1, 3], [0, 2]]
57+
<strong>Output:</strong> 4
58+
</pre>
59+
60+
<p>&nbsp;</p>
61+
<p><strong>Constraints:</strong></p>
62+
63+
<ul>
64+
<li><code>2 &lt;= n &lt;= 500</code></li>
65+
<li><code>n</code>&nbsp;is even.</li>
66+
<li><code>preferences.length&nbsp;== n</code></li>
67+
<li><code>preferences[i].length&nbsp;== n - 1</code></li>
68+
<li><code>0 &lt;= preferences[i][j] &lt;= n - 1</code></li>
69+
<li><code>preferences[i]</code>&nbsp;does not contain <code>i</code>.</li>
70+
<li>All values in&nbsp;<code>preferences[i]</code>&nbsp;are unique.</li>
71+
<li><code>pairs.length&nbsp;== n/2</code></li>
72+
<li><code>pairs[i].length&nbsp;== 2</code></li>
73+
<li><code>x<sub>i</sub> != y<sub>i</sub></code></li>
74+
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub>&nbsp;&lt;= n - 1</code></li>
75+
<li>Each person is contained in <strong>exactly one</strong> pair.</li>
76+
</ul>
77+
78+
### Related Topics
79+
[[Array](../../tag/array/README.md)]
80+
81+
### Hints
82+
<details>
83+
<summary>Hint 1</summary>
84+
Create a matrix "rank" where rank[i][j] holds how highly friend ‘i' views ‘j’. This allows for O(1) comparisons between people
85+
</details>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <openset.wang@gmail.com> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../put-boxes-into-the-warehouse-ii "Put Boxes Into the Warehouse II")
9+
10+
[Next >](../special-positions-in-a-binary-matrix "Special Positions in a Binary Matrix")
11+
12+
## [1581. Customer Who Visited but Did Not Make Any Transactions (Easy)](https://leetcode.com/problems/customer-who-visited-but-did-not-make-any-transactions "")
13+
14+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Create table If Not Exists Visits(visit_id int, customer_id int);
2+
Create table If Not Exists Transactions(transaction_id int, visit_id int, amount int);
3+
Truncate table Visits;
4+
insert into Visits (visit_id, customer_id) values ('1', '23');
5+
insert into Visits (visit_id, customer_id) values ('2', '9');
6+
insert into Visits (visit_id, customer_id) values ('4', '30');
7+
insert into Visits (visit_id, customer_id) values ('5', '54');
8+
insert into Visits (visit_id, customer_id) values ('6', '96');
9+
insert into Visits (visit_id, customer_id) values ('7', '54');
10+
insert into Visits (visit_id, customer_id) values ('8', '54');
11+
Truncate table Transactions;
12+
insert into Transactions (transaction_id, visit_id, amount) values ('2', '5', '310');
13+
insert into Transactions (transaction_id, visit_id, amount) values ('3', '5', '300');
14+
insert into Transactions (transaction_id, visit_id, amount) values ('9', '5', '200');
15+
insert into Transactions (transaction_id, visit_id, amount) values ('12', '1', '910');
16+
insert into Transactions (transaction_id, visit_id, amount) values ('13', '2', '970');

‎problems/design-a-file-sharing-system/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
### Related Topics
17+
[[Design](../../tag/design/README.md)]
1718
[[Array](../../tag/array/README.md)]
1819

1920
### Hints

‎problems/design-compressed-string-iterator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ iterator.next(); // return ' '
5353

5454
### Similar Questions
5555
1. [LRU Cache](../lru-cache) (Medium)
56-
1. [String Compression](../string-compression) (Easy)
56+
1. [String Compression](../string-compression) (Medium)

‎problems/encode-and-decode-strings/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ vector&lt;string&gt; strs2 = decode(encoded_string);
6161
### Similar Questions
6262
1. [Count and Say](../count-and-say) (Easy)
6363
1. [Serialize and Deserialize Binary Tree](../serialize-and-deserialize-binary-tree) (Hard)
64-
1. [String Compression](../string-compression) (Easy)
64+
1. [String Compression](../string-compression) (Medium)
6565
1. [Count Binary Substrings](../count-binary-substrings) (Easy)

0 commit comments

Comments
(0)

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