Skip to content

Add: new #546

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 19, 2019
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1049">1049</span> | [Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii "最后一块石头的重量 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight-ii) | Medium |
| <span id="1048">1048</span> | [Longest String Chain](https://leetcode.com/problems/longest-string-chain "最长字符串链") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain) | Medium |
| <span id="1047">1047</span> | [Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string "删除字符串中的所有相邻重复项") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-all-adjacent-duplicates-in-string) | Easy |
| <span id="1046">1046</span> | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight "最后一块石头的重量") | [Go](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight) | Easy |
| <span id="1045">1045</span> | [Customers Who Bought All Products](https://leetcode.com/problems/customers-who-bought-all-products) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/customers-who-bought-all-products) | Medium |
| <span id="1044">1044</span> | [Longest Duplicate Substring](https://leetcode.com/problems/longest-duplicate-substring "最长重复子串") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-duplicate-substring) | Hard |
| <span id="1043">1043</span> | [Partition Array for Maximum Sum](https://leetcode.com/problems/partition-array-for-maximum-sum "分隔数组以得到最大和") | [Go](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum) | Medium |
| <span id="1042">1042</span> | [Flower Planting With No Adjacent](https://leetcode.com/problems/flower-planting-with-no-adjacent "不邻接植花") | [Go](https://github.com/openset/leetcode/tree/master/problems/flower-planting-with-no-adjacent) | Easy |
Expand Down
14 changes: 14 additions & 0 deletions problems/customers-who-bought-all-products/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 <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/longest-duplicate-substring "Longest Duplicate Substring")

[Next >](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight "Last Stone Weight")

## 1045. Customers Who Bought All Products (Medium)


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Write your MySQL query statement below
11 changes: 11 additions & 0 deletions problems/customers-who-bought-all-products/mysql_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Create table If Not Exists Customer (customer_id int, product_key int);
Create table Product (product_key int);
Truncate table Customer;
insert into Customer (customer_id, product_key) values ('1', '5');
insert into Customer (customer_id, product_key) values ('2', '6');
insert into Customer (customer_id, product_key) values ('3', '5');
insert into Customer (customer_id, product_key) values ('3', '6');
insert into Customer (customer_id, product_key) values ('1', '6');
Truncate table Product;
insert into Product (product_key) values ('5');
insert into Product (product_key) values ('6');
46 changes: 46 additions & 0 deletions problems/last-stone-weight-ii/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain "Longest String Chain")

Next >

## 1049. Last Stone Weight II (Medium)

<p>We have a collection of rocks, each rock has a positive integer weight.</p>

<p>Each turn, we choose <strong>any two rocks</strong>&nbsp;and smash them together.&nbsp; Suppose the stones have weights <code>x</code> and <code>y</code> with <code>x &lt;= y</code>.&nbsp; The result of this smash is:</p>

<ul>
<li>If <code>x == y</code>, both stones are totally destroyed;</li>
<li>If <code>x != y</code>, the stone of weight <code>x</code> is totally destroyed, and the stone of weight <code>y</code> has new weight <code>y-x</code>.</li>
</ul>

<p>At the end, there is at most 1 stone left.&nbsp; Return the <strong>smallest possible</strong> weight of this stone (the weight is&nbsp;0 if there are no stones left.)</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong>[2,7,4,1,8,1]
<strong>Output: </strong>1
<strong>Explanation: </strong>
We can combine 2 and 4 to get 2 so the array converts to [2,7,1,8,1] then,
we can combine 7 and 8 to get 1 so the array converts to [2,1,1,1] then,
we can combine 2 and 1 to get 1 so the array converts to [1,1,1] then,
we can combine 1 and 1 to get 0 so the array converts to [1] then that&#39;s the optimal value.
</pre>

<p>&nbsp;</p>

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

<ol>
<li><code>1 &lt;= stones.length &lt;= 30</code></li>
<li><code>1 &lt;= stones[i] &lt;= 100</code></li>
</ol>
30 changes: 30 additions & 0 deletions problems/last-stone-weight/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/customers-who-bought-all-products "Customers Who Bought All Products")

[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-all-adjacent-duplicates-in-string "Remove All Adjacent Duplicates In String")

## 1046. Last Stone Weight (Easy)

<p>We have a collection of rocks, each rock has a positive integer weight.</p>

<p>Each turn, we choose the two <strong>heaviest</strong>&nbsp;rocks&nbsp;and smash them together.&nbsp; Suppose the stones have weights <code>x</code> and <code>y</code> with <code>x &lt;= y</code>.&nbsp; The result of this smash is:</p>

<ul>
<li>If <code>x == y</code>, both stones are totally destroyed;</li>
<li>If <code>x != y</code>, the stone of weight <code>x</code> is totally destroyed, and the stone of weight <code>y</code> has new weight <code>y-x</code>.</li>
</ul>

<p>At the end, there is at most 1 stone left.&nbsp; Return the weight of this stone (or 0 if there are no stones left.)</p>

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

<ol>
<li><code>1 &lt;= stones.length &lt;= 30</code></li>
<li><code>1 &lt;= stones[i] &lt;= 1000</code></li>
</ol>
2 changes: 1 addition & 1 deletion problems/longest-duplicate-substring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[< Previous](https://github.com/openset/leetcode/tree/master/problems/partition-array-for-maximum-sum "Partition Array for Maximum Sum")

Next >
[Next >](https://github.com/openset/leetcode/tree/master/problems/customers-who-bought-all-products "Customers Who Bought All Products")

## 1044. Longest Duplicate Substring (Hard)

Expand Down
44 changes: 44 additions & 0 deletions problems/longest-string-chain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/remove-all-adjacent-duplicates-in-string "Remove All Adjacent Duplicates In String")

[Next >](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight-ii "Last Stone Weight II")

## 1048. Longest String Chain (Medium)

<p>Given a list of words, each word consists of English lowercase letters.</p>

<p>Let&#39;s say <code>word1</code> is a predecessor of <code>word2</code>&nbsp;if and only if we can add exactly one letter anywhere in <code>word1</code> to make it equal to <code>word2</code>.&nbsp; For example,&nbsp;<code>&quot;abc&quot;</code>&nbsp;is a predecessor of <code>&quot;abac&quot;</code>.</p>

<p>A <em>word chain&nbsp;</em>is a sequence of words <code>[word_1, word_2, ..., word_k]</code>&nbsp;with <code>k &gt;= 1</code>,&nbsp;where <code>word_1</code> is a predecessor of <code>word_2</code>, <code>word_2</code> is a predecessor of <code>word_3</code>, and so on.</p>

<p>Return the longest possible length of a word chain with words chosen from the given list of <code>words</code>.</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong><span id="example-input-1-1">[&quot;a&quot;,&quot;b&quot;,&quot;ba&quot;,&quot;bca&quot;,&quot;bda&quot;,&quot;bdca&quot;]</span>
<strong>Output: </strong><span id="example-output-1">4
<strong>Explanation</strong>: one of </span>the longest word chain is &quot;a&quot;,&quot;ba&quot;,&quot;bda&quot;,&quot;bdca&quot;.
</pre>

<p>&nbsp;</p>

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

<ol>
<li><code>1 &lt;= words.length &lt;= 1000</code></li>
<li><code>1 &lt;= words[i].length &lt;= 16</code></li>
<li><code>words[i]</code> only consists of English lowercase letters.</li>
</ol>

<div>
<p>&nbsp;</p>
</div>
38 changes: 38 additions & 0 deletions problems/remove-all-adjacent-duplicates-in-string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
<!--+----------------------------------------------------------------------+-->
<!--|@author Openset <[email protected]> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight "Last Stone Weight")

[Next >](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain "Longest String Chain")

## 1047. Remove All Adjacent Duplicates In String (Easy)

<p>Given a string <code>S</code> of lowercase letters, a <em>duplicate removal</em> consists of choosing two adjacent and equal letters, and removing&nbsp;them.</p>

<p>We repeatedly make duplicate removals on S until we no longer can.</p>

<p>Return the final string after all such duplicate removals have been made.&nbsp; It is guaranteed the answer is unique.</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong><span id="example-input-1-1">&quot;abbaca&quot;</span>
<strong>Output: </strong><span id="example-output-1">&quot;ca&quot;</span>
<strong>Explanation: </strong>
For example, in &quot;abbaca&quot; we could remove &quot;bb&quot; since the letters are adjacent and equal, and this is the only possible move.&nbsp; The result of this move is that the string is &quot;aaca&quot;, of which only &quot;aa&quot; is possible, so the final string is &quot;ca&quot;.
</pre>

<p>&nbsp;</p>

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

<ol>
<li><code>1 &lt;= S.length &lt;= 20000</code></li>
<li><code>S</code> consists only of English lowercase letters.</li>
</ol>