Skip to content

Commit 6a926fa

Browse files
author
Shuo
authored
Merge pull request #790 from openset/develop
A: new
2 parents b259efe + f9b69bc commit 6a926fa

File tree

26 files changed

+396
-50
lines changed

26 files changed

+396
-50
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ LeetCode Problems' Solutions
6262

6363
| # | Title | Solution | Difficulty |
6464
| :-: | - | - | :-: |
65+
| <span id="1458">1458</span> | [Max Dot Product of Two Subsequences](https://leetcode.com/problems/max-dot-product-of-two-subsequences "两个子序列的最大点积") | [Go](problems/max-dot-product-of-two-subsequences) | Hard |
66+
| <span id="1457">1457</span> | [Pseudo-Palindromic Paths in a Binary Tree](https://leetcode.com/problems/pseudo-palindromic-paths-in-a-binary-tree "二叉树中的伪回文路径") | [Go](problems/pseudo-palindromic-paths-in-a-binary-tree) | Medium |
67+
| <span id="1456">1456</span> | [Maximum Number of Vowels in a Substring of Given Length](https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length "定长子串中元音的最大数目") | [Go](problems/maximum-number-of-vowels-in-a-substring-of-given-length) | Medium |
68+
| <span id="1455">1455</span> | [Check If a Word Occurs As a Prefix of Any Word in a Sentence](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence "检查单词是否为句中其他单词的前缀") | [Go](problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence) | Easy |
69+
| <span id="1454">1454</span> | [Active Users](https://leetcode.com/problems/active-users) 🔒 | [MySQL](problems/active-users) | Medium |
6570
| <span id="1453">1453</span> | [Maximum Number of Darts Inside of a Circular Dartboard](https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard "圆形靶内的最大飞镖数量") | [Go](problems/maximum-number-of-darts-inside-of-a-circular-dartboard) | Hard |
6671
| <span id="1452">1452</span> | [People Whose List of Favorite Companies Is Not a Subset of Another List](https://leetcode.com/problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list "收藏清单") | [Go](problems/people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list) | Medium |
6772
| <span id="1451">1451</span> | [Rearrange Words in a Sentence](https://leetcode.com/problems/rearrange-words-in-a-sentence "重新排列句子中的单词") | [Go](problems/rearrange-words-in-a-sentence) | Medium |
@@ -70,7 +75,7 @@ LeetCode Problems' Solutions
7075
| <span id="1448">1448</span> | [Count Good Nodes in Binary Tree](https://leetcode.com/problems/count-good-nodes-in-binary-tree "统计二叉树中好节点的数目") | [Go](problems/count-good-nodes-in-binary-tree) | Medium |
7176
| <span id="1447">1447</span> | [Simplified Fractions](https://leetcode.com/problems/simplified-fractions "最简分数") | [Go](problems/simplified-fractions) | Medium |
7277
| <span id="1446">1446</span> | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters "连续字符") | [Go](problems/consecutive-characters) | Easy |
73-
| <span id="1445">1445</span> | [Apples & Oranges](https://leetcode.com/problems/apples-oranges) 🔒 | [MySQL](problems/apples-oranges) | Medium |
78+
| <span id="1445">1445</span> | [Apples & Oranges](https://leetcode.com/problems/apples-oranges "苹果和桔子") 🔒 | [MySQL](problems/apples-oranges) | Medium |
7479
| <span id="1444">1444</span> | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza "切披萨的方案数") | [Go](problems/number-of-ways-of-cutting-a-pizza) | Hard |
7580
| <span id="1443">1443</span> | [Minimum Time to Collect All Apples in a Tree](https://leetcode.com/problems/minimum-time-to-collect-all-apples-in-a-tree "收集树上所有苹果的最少时间") | [Go](problems/minimum-time-to-collect-all-apples-in-a-tree) | Medium |
7681
| <span id="1442">1442</span> | [Count Triplets That Can Form Two Arrays of Equal XOR](https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor "形成两个异或相等数组的三元组数目") | [Go](problems/count-triplets-that-can-form-two-arrays-of-equal-xor) | Medium |
@@ -87,7 +92,7 @@ LeetCode Problems' Solutions
8792
| <span id="1431">1431</span> | [Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies "拥有最多糖果的孩子") | [Go](problems/kids-with-the-greatest-number-of-candies) | Easy |
8893
| <span id="1430">1430</span> | [Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree](https://leetcode.com/problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) 🔒 | [Go](problems/check-if-a-string-is-a-valid-sequence-from-root-to-leaves-path-in-a-binary-tree) | Medium |
8994
| <span id="1429">1429</span> | [First Unique Number](https://leetcode.com/problems/first-unique-number) 🔒 | [Go](problems/first-unique-number) | Medium |
90-
| <span id="1428">1428</span> | [Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one) 🔒 | [Go](problems/leftmost-column-with-at-least-a-one) | Medium |
95+
| <span id="1428">1428</span> | [Leftmost Column with at Least a One](https://leetcode.com/problems/leftmost-column-with-at-least-a-one "至少有一个 1 的最左端列") 🔒 | [Go](problems/leftmost-column-with-at-least-a-one) | Medium |
9196
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts) 🔒 | [Go](problems/perform-string-shifts) | Easy |
9297
| <span id="1426">1426</span> | [Counting Elements](https://leetcode.com/problems/counting-elements "数元素") 🔒 | [Go](problems/counting-elements) | Easy |
9398
| <span id="1425">1425</span> | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和") | [Go](problems/constrained-subsequence-sum) | Hard |

problems/active-users/README.md

+14
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 <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../maximum-number-of-darts-inside-of-a-circular-dartboard "Maximum Number of Darts Inside of a Circular Dartboard")
9+
                
10+
[Next >](../check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence "Check If a Word Occurs As a Prefix of Any Word in a Sentence")
11+
12+
## [1454. Active Users (Medium)](https://leetcode.com/problems/active-users "")
13+
14+
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Create table If Not Exists Accounts (id int, name varchar(10));
2+
Create table If Not Exists Logins (id int, login_date date);
3+
Truncate table Accounts;
4+
insert into Accounts (id, name) values ('1', 'Winston');
5+
insert into Accounts (id, name) values ('7', 'Jonathan');
6+
Truncate table Logins;
7+
insert into Logins (id, login_date) values ('7', '2020-05-30');
8+
insert into Logins (id, login_date) values ('1', '2020-05-30');
9+
insert into Logins (id, login_date) values ('7', '2020-05-31');
10+
insert into Logins (id, login_date) values ('7', '2020-06-01');
11+
insert into Logins (id, login_date) values ('7', '2020-06-02');
12+
insert into Logins (id, login_date) values ('7', '2020-06-02');
13+
insert into Logins (id, login_date) values ('7', '2020-06-03');
14+
insert into Logins (id, login_date) values ('1', '2020-06-07');
15+
insert into Logins (id, login_date) values ('7', '2020-06-10');

problems/apples-oranges/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
[Next >](../consecutive-characters "Consecutive Characters")
1111

12-
## [1445. Apples & Oranges (Medium)](https://leetcode.com/problems/apples-oranges "")
12+
## [1445. Apples & Oranges (Medium)](https://leetcode.com/problems/apples-oranges "苹果和桔子")
1313

1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../active-users "Active Users")
9+
                
10+
[Next >](../maximum-number-of-vowels-in-a-substring-of-given-length "Maximum Number of Vowels in a Substring of Given Length")
11+
12+
## [1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence (Easy)](https://leetcode.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence "检查单词是否为句中其他单词的前缀")
13+
14+
<p>Given a <code>sentence</code>&nbsp;that consists of some words separated by a&nbsp;<strong>single space</strong>, and a <code>searchWord</code>.</p>
15+
16+
<p>You have to check if <code>searchWord</code> is a prefix of any word in <code>sentence</code>.</p>
17+
18+
<p>Return <em>the index of the word</em> in <code>sentence</code> where <code>searchWord</code> is a prefix of this word (<strong>1-indexed</strong>).</p>
19+
20+
<p>If <code>searchWord</code> is&nbsp;a prefix of more than one word, return the index of the first word <strong>(minimum index)</strong>. If there is no such word return <strong>-1</strong>.</p>
21+
22+
<p>A <strong>prefix</strong> of a string&nbsp;<code>S</code> is any leading contiguous substring of <code>S</code>.</p>
23+
24+
<p>&nbsp;</p>
25+
<p><strong>Example 1:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> sentence = &quot;i love eating burger&quot;, searchWord = &quot;burg&quot;
29+
<strong>Output:</strong> 4
30+
<strong>Explanation:</strong> &quot;burg&quot; is prefix of &quot;burger&quot; which is the 4th word in the sentence.
31+
</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> sentence = &quot;this problem is an easy problem&quot;, searchWord = &quot;pro&quot;
37+
<strong>Output:</strong> 2
38+
<strong>Explanation:</strong> &quot;pro&quot; is prefix of &quot;problem&quot; which is the 2nd and the 6th word in the sentence, but we return 2 as it&#39;s the minimal index.
39+
</pre>
40+
41+
<p><strong>Example 3:</strong></p>
42+
43+
<pre>
44+
<strong>Input:</strong> sentence = &quot;i am tired&quot;, searchWord = &quot;you&quot;
45+
<strong>Output:</strong> -1
46+
<strong>Explanation:</strong> &quot;you&quot; is not a prefix of any word in the sentence.
47+
</pre>
48+
49+
<p><strong>Example 4:</strong></p>
50+
51+
<pre>
52+
<strong>Input:</strong> sentence = &quot;i use triple pillow&quot;, searchWord = &quot;pill&quot;
53+
<strong>Output:</strong> 4
54+
</pre>
55+
56+
<p><strong>Example 5:</strong></p>
57+
58+
<pre>
59+
<strong>Input:</strong> sentence = &quot;hello from the other side&quot;, searchWord = &quot;they&quot;
60+
<strong>Output:</strong> -1
61+
</pre>
62+
63+
<p>&nbsp;</p>
64+
<p><strong>Constraints:</strong></p>
65+
66+
<ul>
67+
<li><code>1 &lt;= sentence.length &lt;= 100</code></li>
68+
<li><code>1 &lt;= searchWord.length &lt;= 10</code></li>
69+
<li><code>sentence</code> consists of lowercase English letters and spaces.</li>
70+
<li><code>searchWord</code>&nbsp;consists of lowercase English letters.</li>
71+
</ul>
72+
73+
### Related Topics
74+
[[String](../../tag/string/README.md)]
75+
76+
### Hints
77+
<details>
78+
<summary>Hint 1</summary>
79+
First extract the words of the sentence.
80+
</details>
81+
82+
<details>
83+
<summary>Hint 2</summary>
84+
Check for each word if searchWord occurs at index 0, if so return the index of this word (1-indexed)
85+
</details>
86+
87+
<details>
88+
<summary>Hint 3</summary>
89+
If searchWord doesn't exist as a prefix of any word return the default value (-1).
90+
</details>

problems/count-different-palindromic-subsequences/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../my-calendar-ii "My Calendar II")
1111

12-
## [730. Count Different Palindromic Subsequences (Hard)](https://leetcode.com/problems/count-different-palindromic-subsequences "统计不同回文子字符串")
12+
## [730. Count Different Palindromic Subsequences (Hard)](https://leetcode.com/problems/count-different-palindromic-subsequences "统计不同回文子序列")
1313

1414
<p>
1515
Given a string S, find the number of different non-empty palindromic subsequences in S, and <b>return that number modulo <code>10^9 + 7</code>.</b>

problems/find-peak-element/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
&nbsp; or index number 5 where the peak element is 6.
3636
</pre>
3737

38-
<p><strong>Note:</strong></p>
39-
40-
<p>Your solution should be in logarithmic complexity.</p>
38+
<p><strong>Follow up:</strong>&nbsp;Your solution should be in logarithmic complexity.</p>
4139

4240
### Related Topics
4341
[[Array](../../tag/array/README.md)]

problems/find-pivot-index/README.md

+11-17
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,38 @@
1313

1414
<p>Given an array of integers <code>nums</code>, write a method that returns the &quot;pivot&quot; index of this array.</p>
1515

16-
<p>We define the pivot index as the index where the sum of the numbers to the left of the index is equal to the sum of the numbers to the right of the index.</p>
16+
<p>We define the pivot index as the index where the sum of all the numbers to the left of the index is equal to the sum of all the numbers to the right of the index.</p>
1717

1818
<p>If no such index exists, we should return -1. If there are multiple pivot indexes, you should return the left-most pivot index.</p>
1919

20-
<p><b>Example 1:</b></p>
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
2122

2223
<pre>
23-
<b>Input:</b>
24-
nums = [1, 7, 3, 6, 5, 6]
25-
<b>Output:</b> 3
26-
<b>Explanation:</b>
24+
<strong>Input:</strong> nums = [1,7,3,6,5,6]
25+
<strong>Output:</strong> 3
26+
<strong>Explanation:</strong>
2727
The sum of the numbers to the left of index 3 (nums[3] = 6) is equal to the sum of numbers to the right of index 3.
2828
Also, 3 is the first index where this occurs.
2929
</pre>
3030

31-
<p>&nbsp;</p>
32-
33-
<p><b>Example 2:</b></p>
31+
<p><strong>Example 2:</strong></p>
3432

3533
<pre>
36-
<b>Input:</b>
37-
nums = [1, 2, 3]
38-
<b>Output:</b> -1
39-
<b>Explanation:</b>
34+
<strong>Input:</strong> nums = [1,2,3]
35+
<strong>Output:</strong> -1
36+
<strong>Explanation:</strong>
4037
There is no index that satisfies the conditions in the problem statement.
4138
</pre>
4239

4340
<p>&nbsp;</p>
44-
45-
<p><b>Note:</b></p>
41+
<p><strong>Constraints:</strong></p>
4642

4743
<ul>
4844
<li>The length of <code>nums</code> will be in the range <code>[0, 10000]</code>.</li>
4945
<li>Each element <code>nums[i]</code> will be an integer in the range <code>[-1000, 1000]</code>.</li>
5046
</ul>
5147

52-
<p>&nbsp;</p>
53-
5448
### Related Topics
5549
[[Array](../../tag/array/README.md)]
5650

problems/form-largest-integer-with-digits-that-add-up-to-target/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<pre>
3030
<strong>Input:</strong> cost = [4,3,2,5,6,7,2,5,5], target = 9
3131
<strong>Output:</strong> &quot;7772&quot;
32-
<strong>Explanation: </strong> The cost to paint the digit &#39;7&#39; is 2, and the digit &#39;2&#39; is 3. Then cost(&quot;7772&quot;) = 2*3+ 3*1 = 9. You could also paint &quot;997&quot;, but &quot;7772&quot; is the largest number.
32+
<strong>Explanation: </strong> The cost to paint the digit &#39;7&#39; is 2, and the digit &#39;2&#39; is 3. Then cost(&quot;7772&quot;) = 2*3+ 3*1 = 9. You could also paint &quot;977&quot;, but &quot;7772&quot; is the largest number.
3333
<strong>Digit cost</strong>
3434
1 -&gt; 4
3535
2 -&gt; 3

problems/kth-smallest-element-in-a-bst/README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
<p>Given a binary search tree, write a function <code>kthSmallest</code> to find the <b>k</b>th smallest element in it.</p>
1515

16-
<p><b>Note: </b><br />
17-
You may assume k is always valid, 1 &le; k &le; BST&#39;s total elements.</p>
16+
<p>&nbsp;</p>
1817

1918
<p><strong>Example 1:</strong></p>
2019

@@ -44,6 +43,14 @@ You may assume k is always valid, 1 &le; k &le; BST&#39;s total elements.</p>
4443
<p><b>Follow up:</b><br />
4544
What if the BST is modified (insert/delete operations) often and you need to find the kth smallest frequently? How would you optimize the kthSmallest routine?</p>
4645

46+
<p>&nbsp;</p>
47+
<p><strong>Constraints:</strong></p>
48+
49+
<ul>
50+
<li>The number of elements of the BST is between <code>1</code> to <code>10^4</code>.</li>
51+
<li>You may assume <code>k</code> is always valid, <code>1 &le; k &le; BST&#39;s total elements</code>.</li>
52+
</ul>
53+
4754
### Related Topics
4855
[[Tree](../../tag/tree/README.md)]
4956
[[Binary Search](../../tag/binary-search/README.md)]

problems/leftmost-column-with-at-least-a-one/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](../first-unique-number "First Unique Number")
1111

12-
## [1428. Leftmost Column with at Least a One (Medium)](https://leetcode.com/problems/leftmost-column-with-at-least-a-one "")
12+
## [1428. Leftmost Column with at Least a One (Medium)](https://leetcode.com/problems/leftmost-column-with-at-least-a-one "至少有一个 1 的最左端列")
1313

1414

1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](../pseudo-palindromic-paths-in-a-binary-tree "Pseudo-Palindromic Paths in a Binary Tree")
9+
                
10+
Next >
11+
12+
## [1458. Max Dot Product of Two Subsequences (Hard)](https://leetcode.com/problems/max-dot-product-of-two-subsequences "两个子序列的最大点积")
13+
14+
<p>Given two arrays <code>nums1</code>&nbsp;and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>
15+
16+
<p>Return the maximum dot product&nbsp;between&nbsp;<strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>
17+
18+
<p>A subsequence of a array is a new array which is formed from the original array by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie,&nbsp;<code>[2,3,5]</code>&nbsp;is a subsequence of&nbsp;<code>[1,2,3,4,5]</code>&nbsp;while <code>[1,5,3]</code>&nbsp;is not).</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums1 = [2,1,-2,5], nums2 = [3,0,-6]
25+
<strong>Output:</strong> 18
26+
<strong>Explanation:</strong> Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.
27+
Their dot product is (2*3 + (-2)*(-6)) = 18.</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> nums1 = [3,-2], nums2 = [2,-6,7]
33+
<strong>Output:</strong> 21
34+
<strong>Explanation:</strong> Take subsequence [3] from nums1 and subsequence [7] from nums2.
35+
Their dot product is (3*7) = 21.</pre>
36+
37+
<p><strong>Example 3:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> nums1 = [-1,-1], nums2 = [1,1]
41+
<strong>Output:</strong> -1
42+
<strong>Explanation: </strong>Take subsequence [-1] from nums1 and subsequence [1] from nums2.
43+
Their dot product is -1.</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 500</code></li>
50+
<li><code>-1000 &lt;= nums1[i], nums2[i] &lt;= 1000</code></li>
51+
</ul>
52+
53+
### Related Topics
54+
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]
55+
56+
### Hints
57+
<details>
58+
<summary>Hint 1</summary>
59+
Use dynamic programming, define DP[i][j] as the maximum dot product of two subsequences starting in the position i of nums1 and position j of nums2.
60+
</details>

problems/maximum-number-of-darts-inside-of-a-circular-dartboard/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](../people-whose-list-of-favorite-companies-is-not-a-subset-of-another-list "People Whose List of Favorite Companies Is Not a Subset of Another List")
99

10-
Next >
10+
[Next >](../active-users "Active Users")
1111

1212
## [1453. Maximum Number of Darts Inside of a Circular Dartboard (Hard)](https://leetcode.com/problems/maximum-number-of-darts-inside-of-a-circular-dartboard "圆形靶内的最大飞镖数量")
1313

0 commit comments

Comments
 (0)