Skip to content

A: new #790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <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 |
| <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 |
| <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 |
| <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 |
| <span id="1454">1454</span> | [Active Users](https://leetcode.com/problems/active-users) 🔒 | [MySQL](problems/active-users) | Medium |
| <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 |
| <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 |
| <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 |
Expand All @@ -70,7 +75,7 @@ LeetCode Problems' Solutions
| <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 |
| <span id="1447">1447</span> | [Simplified Fractions](https://leetcode.com/problems/simplified-fractions "最简分数") | [Go](problems/simplified-fractions) | Medium |
| <span id="1446">1446</span> | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters "连续字符") | [Go](problems/consecutive-characters) | Easy |
| <span id="1445">1445</span> | [Apples & Oranges](https://leetcode.com/problems/apples-oranges) 🔒 | [MySQL](problems/apples-oranges) | Medium |
| <span id="1445">1445</span> | [Apples & Oranges](https://leetcode.com/problems/apples-oranges "苹果和桔子") 🔒 | [MySQL](problems/apples-oranges) | Medium |
| <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 |
| <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 |
| <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 |
Expand All @@ -87,7 +92,7 @@ LeetCode Problems' Solutions
| <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 |
| <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 |
| <span id="1429">1429</span> | [First Unique Number](https://leetcode.com/problems/first-unique-number) 🔒 | [Go](problems/first-unique-number) | Medium |
| <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 |
| <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 |
| <span id="1427">1427</span> | [Perform String Shifts](https://leetcode.com/problems/perform-string-shifts) 🔒 | [Go](problems/perform-string-shifts) | Easy |
| <span id="1426">1426</span> | [Counting Elements](https://leetcode.com/problems/counting-elements "数元素") 🔒 | [Go](problems/counting-elements) | Easy |
| <span id="1425">1425</span> | [Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum "带限制的子序列和") | [Go](problems/constrained-subsequence-sum) | Hard |
Expand Down
14 changes: 14 additions & 0 deletions problems/active-users/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../maximum-number-of-darts-inside-of-a-circular-dartboard "Maximum Number of Darts Inside of a Circular Dartboard")

[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")

## [1454. Active Users (Medium)](https://leetcode.com/problems/active-users "")


15 changes: 15 additions & 0 deletions problems/active-users/mysql_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Create table If Not Exists Accounts (id int, name varchar(10));
Create table If Not Exists Logins (id int, login_date date);
Truncate table Accounts;
insert into Accounts (id, name) values ('1', 'Winston');
insert into Accounts (id, name) values ('7', 'Jonathan');
Truncate table Logins;
insert into Logins (id, login_date) values ('7', '2020-05-30');
insert into Logins (id, login_date) values ('1', '2020-05-30');
insert into Logins (id, login_date) values ('7', '2020-05-31');
insert into Logins (id, login_date) values ('7', '2020-06-01');
insert into Logins (id, login_date) values ('7', '2020-06-02');
insert into Logins (id, login_date) values ('7', '2020-06-02');
insert into Logins (id, login_date) values ('7', '2020-06-03');
insert into Logins (id, login_date) values ('1', '2020-06-07');
insert into Logins (id, login_date) values ('7', '2020-06-10');
2 changes: 1 addition & 1 deletion problems/apples-oranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

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

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


Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../active-users "Active Users")

[Next >](../maximum-number-of-vowels-in-a-substring-of-given-length "Maximum Number of Vowels in a Substring of Given Length")

## [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 "检查单词是否为句中其他单词的前缀")

<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>

<p>You have to check if <code>searchWord</code> is a prefix of any word in <code>sentence</code>.</p>

<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>

<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>

<p>A <strong>prefix</strong> of a string&nbsp;<code>S</code> is any leading contiguous substring of <code>S</code>.</p>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> sentence = &quot;i love eating burger&quot;, searchWord = &quot;burg&quot;
<strong>Output:</strong> 4
<strong>Explanation:</strong> &quot;burg&quot; is prefix of &quot;burger&quot; which is the 4th word in the sentence.
</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> sentence = &quot;this problem is an easy problem&quot;, searchWord = &quot;pro&quot;
<strong>Output:</strong> 2
<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.
</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> sentence = &quot;i am tired&quot;, searchWord = &quot;you&quot;
<strong>Output:</strong> -1
<strong>Explanation:</strong> &quot;you&quot; is not a prefix of any word in the sentence.
</pre>

<p><strong>Example 4:</strong></p>

<pre>
<strong>Input:</strong> sentence = &quot;i use triple pillow&quot;, searchWord = &quot;pill&quot;
<strong>Output:</strong> 4
</pre>

<p><strong>Example 5:</strong></p>

<pre>
<strong>Input:</strong> sentence = &quot;hello from the other side&quot;, searchWord = &quot;they&quot;
<strong>Output:</strong> -1
</pre>

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

<ul>
<li><code>1 &lt;= sentence.length &lt;= 100</code></li>
<li><code>1 &lt;= searchWord.length &lt;= 10</code></li>
<li><code>sentence</code> consists of lowercase English letters and spaces.</li>
<li><code>searchWord</code>&nbsp;consists of lowercase English letters.</li>
</ul>

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

### Hints
<details>
<summary>Hint 1</summary>
First extract the words of the sentence.
</details>

<details>
<summary>Hint 2</summary>
Check for each word if searchWord occurs at index 0, if so return the index of this word (1-indexed)
</details>

<details>
<summary>Hint 3</summary>
If searchWord doesn't exist as a prefix of any word return the default value (-1).
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

<p>
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>
Expand Down
4 changes: 1 addition & 3 deletions problems/find-peak-element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
&nbsp; or index number 5 where the peak element is 6.
</pre>

<p><strong>Note:</strong></p>

<p>Your solution should be in logarithmic complexity.</p>
<p><strong>Follow up:</strong>&nbsp;Your solution should be in logarithmic complexity.</p>

### Related Topics
[[Array](../../tag/array/README.md)]
Expand Down
28 changes: 11 additions & 17 deletions problems/find-pivot-index/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,38 @@

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

<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>
<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>

<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>

<p><b>Example 1:</b></p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<b>Input:</b>
nums = [1, 7, 3, 6, 5, 6]
<b>Output:</b> 3
<b>Explanation:</b>
<strong>Input:</strong> nums = [1,7,3,6,5,6]
<strong>Output:</strong> 3
<strong>Explanation:</strong>
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.
Also, 3 is the first index where this occurs.
</pre>

<p>&nbsp;</p>

<p><b>Example 2:</b></p>
<p><strong>Example 2:</strong></p>

<pre>
<b>Input:</b>
nums = [1, 2, 3]
<b>Output:</b> -1
<b>Explanation:</b>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong>
There is no index that satisfies the conditions in the problem statement.
</pre>

<p>&nbsp;</p>

<p><b>Note:</b></p>
<p><strong>Constraints:</strong></p>

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

<p>&nbsp;</p>

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<pre>
<strong>Input:</strong> cost = [4,3,2,5,6,7,2,5,5], target = 9
<strong>Output:</strong> &quot;7772&quot;
<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.
<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.
<strong>Digit cost</strong>
1 -&gt; 4
2 -&gt; 3
Expand Down
11 changes: 9 additions & 2 deletions problems/kth-smallest-element-in-a-bst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

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

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

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

Expand Down Expand Up @@ -44,6 +43,14 @@ You may assume k is always valid, 1 &le; k &le; BST&#39;s total elements.</p>
<p><b>Follow up:</b><br />
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>

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

<ul>
<li>The number of elements of the BST is between <code>1</code> to <code>10^4</code>.</li>
<li>You may assume <code>k</code> is always valid, <code>1 &le; k &le; BST&#39;s total elements</code>.</li>
</ul>

### Related Topics
[[Tree](../../tag/tree/README.md)]
[[Binary Search](../../tag/binary-search/README.md)]
Expand Down
2 changes: 1 addition & 1 deletion problems/leftmost-column-with-at-least-a-one/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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



Expand Down
60 changes: 60 additions & 0 deletions problems/max-dot-product-of-two-subsequences/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author openset <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](../pseudo-palindromic-paths-in-a-binary-tree "Pseudo-Palindromic Paths in a Binary Tree")

Next >

## [1458. Max Dot Product of Two Subsequences (Hard)](https://leetcode.com/problems/max-dot-product-of-two-subsequences "两个子序列的最大点积")

<p>Given two arrays <code>nums1</code>&nbsp;and <code><font face="monospace">nums2</font></code><font face="monospace">.</font></p>

<p>Return the maximum dot product&nbsp;between&nbsp;<strong>non-empty</strong> subsequences of nums1 and nums2 with the same length.</p>

<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>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [2,1,-2,5], nums2 = [3,0,-6]
<strong>Output:</strong> 18
<strong>Explanation:</strong> Take subsequence [2,-2] from nums1 and subsequence [3,-6] from nums2.
Their dot product is (2*3 + (-2)*(-6)) = 18.</pre>

<p><strong>Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [3,-2], nums2 = [2,-6,7]
<strong>Output:</strong> 21
<strong>Explanation:</strong> Take subsequence [3] from nums1 and subsequence [7] from nums2.
Their dot product is (3*7) = 21.</pre>

<p><strong>Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [-1,-1], nums2 = [1,1]
<strong>Output:</strong> -1
<strong>Explanation: </strong>Take subsequence [-1] from nums1 and subsequence [1] from nums2.
Their dot product is -1.</pre>

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

<ul>
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 500</code></li>
<li><code>-1000 &lt;= nums1[i], nums2[i] &lt;= 1000</code></li>
</ul>

### Related Topics
[[Dynamic Programming](../../tag/dynamic-programming/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
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.
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< 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")

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

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

Expand Down
Loading