From 10ef77b27be9982d817edacc2a5953b3443b1999 Mon Sep 17 00:00:00 2001 From: openset Date: Sun, 19 May 2019 16:35:39 +0800 Subject: [PATCH] Add: new --- README.md | 5 ++ .../README.md | 14 ++++++ .../customers_who_bought_all_products.sql | 1 + .../mysql_schemas.sql | 11 +++++ problems/last-stone-weight-ii/README.md | 46 +++++++++++++++++++ problems/last-stone-weight/README.md | 30 ++++++++++++ .../longest-duplicate-substring/README.md | 2 +- problems/longest-string-chain/README.md | 44 ++++++++++++++++++ .../README.md | 38 +++++++++++++++ 9 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 problems/customers-who-bought-all-products/README.md create mode 100644 problems/customers-who-bought-all-products/customers_who_bought_all_products.sql create mode 100644 problems/customers-who-bought-all-products/mysql_schemas.sql create mode 100644 problems/last-stone-weight-ii/README.md create mode 100644 problems/last-stone-weight/README.md create mode 100644 problems/longest-string-chain/README.md create mode 100644 problems/remove-all-adjacent-duplicates-in-string/README.md diff --git a/README.md b/README.md index fceedd62e..c04a16d36 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,11 @@ LeetCode Problems' Solutions | # | Title | Solution | Difficulty | | :-: | - | - | :-: | +| 1049 | [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 | +| 1048 | [Longest String Chain](https://leetcode.com/problems/longest-string-chain "最长字符串链") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain) | Medium | +| 1047 | [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 | +| 1046 | [Last Stone Weight](https://leetcode.com/problems/last-stone-weight "最后一块石头的重量") | [Go](https://github.com/openset/leetcode/tree/master/problems/last-stone-weight) | Easy | +| 1045 | [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 | | 1044 | [Longest Duplicate Substring](https://leetcode.com/problems/longest-duplicate-substring "最长重复子串") | [Go](https://github.com/openset/leetcode/tree/master/problems/longest-duplicate-substring) | Hard | | 1043 | [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 | | 1042 | [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 | diff --git a/problems/customers-who-bought-all-products/README.md b/problems/customers-who-bought-all-products/README.md new file mode 100644 index 000000000..b1b93bb9b --- /dev/null +++ b/problems/customers-who-bought-all-products/README.md @@ -0,0 +1,14 @@ + + + + + + + +[< 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) + + diff --git a/problems/customers-who-bought-all-products/customers_who_bought_all_products.sql b/problems/customers-who-bought-all-products/customers_who_bought_all_products.sql new file mode 100644 index 000000000..bae62cf19 --- /dev/null +++ b/problems/customers-who-bought-all-products/customers_who_bought_all_products.sql @@ -0,0 +1 @@ +# Write your MySQL query statement below diff --git a/problems/customers-who-bought-all-products/mysql_schemas.sql b/problems/customers-who-bought-all-products/mysql_schemas.sql new file mode 100644 index 000000000..ef68a04c1 --- /dev/null +++ b/problems/customers-who-bought-all-products/mysql_schemas.sql @@ -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'); diff --git a/problems/last-stone-weight-ii/README.md b/problems/last-stone-weight-ii/README.md new file mode 100644 index 000000000..0182d9055 --- /dev/null +++ b/problems/last-stone-weight-ii/README.md @@ -0,0 +1,46 @@ + + + + + + + +[< Previous](https://github.com/openset/leetcode/tree/master/problems/longest-string-chain "Longest String Chain") +                 +Next > + +## 1049. Last Stone Weight II (Medium) + +

We have a collection of rocks, each rock has a positive integer weight.

+ +

Each turn, we choose any two rocks and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is:

+ + + +

At the end, there is at most 1 stone left.  Return the smallest possible weight of this stone (the weight is 0 if there are no stones left.)

+ +

 

+ +

Example 1:

+ +
+Input: [2,7,4,1,8,1]
+Output: 1
+Explanation: 
+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's the optimal value.
+
+ +

 

+ +

Note:

+ +
    +
  1. 1 <= stones.length <= 30
  2. +
  3. 1 <= stones[i] <= 100
  4. +
diff --git a/problems/last-stone-weight/README.md b/problems/last-stone-weight/README.md new file mode 100644 index 000000000..e3eab7532 --- /dev/null +++ b/problems/last-stone-weight/README.md @@ -0,0 +1,30 @@ + + + + + + + +[< 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) + +

We have a collection of rocks, each rock has a positive integer weight.

+ +

Each turn, we choose the two heaviest rocks and smash them together.  Suppose the stones have weights x and y with x <= y.  The result of this smash is:

+ + + +

At the end, there is at most 1 stone left.  Return the weight of this stone (or 0 if there are no stones left.)

+ +

Note:

+ +
    +
  1. 1 <= stones.length <= 30
  2. +
  3. 1 <= stones[i] <= 1000
  4. +
diff --git a/problems/longest-duplicate-substring/README.md b/problems/longest-duplicate-substring/README.md index 3aad50c4b..9c2aeb333 100644 --- a/problems/longest-duplicate-substring/README.md +++ b/problems/longest-duplicate-substring/README.md @@ -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) diff --git a/problems/longest-string-chain/README.md b/problems/longest-string-chain/README.md new file mode 100644 index 000000000..bce0bbc14 --- /dev/null +++ b/problems/longest-string-chain/README.md @@ -0,0 +1,44 @@ + + + + + + + +[< 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) + +

Given a list of words, each word consists of English lowercase letters.

+ +

Let's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2.  For example, "abc" is a predecessor of "abac".

+ +

A word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.

+ +

Return the longest possible length of a word chain with words chosen from the given list of words.

+ +

 

+ +

Example 1:

+ +
+Input: ["a","b","ba","bca","bda","bdca"]
+Output: 4
+Explanation: one of the longest word chain is "a","ba","bda","bdca".
+
+ +

 

+ +

Note:

+ +
    +
  1. 1 <= words.length <= 1000
  2. +
  3. 1 <= words[i].length <= 16
  4. +
  5. words[i] only consists of English lowercase letters.
  6. +
+ +
+

 

+
diff --git a/problems/remove-all-adjacent-duplicates-in-string/README.md b/problems/remove-all-adjacent-duplicates-in-string/README.md new file mode 100644 index 000000000..a851fb9d9 --- /dev/null +++ b/problems/remove-all-adjacent-duplicates-in-string/README.md @@ -0,0 +1,38 @@ + + + + + + + +[< 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) + +

Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them.

+ +

We repeatedly make duplicate removals on S until we no longer can.

+ +

Return the final string after all such duplicate removals have been made.  It is guaranteed the answer is unique.

+ +

 

+ +

Example 1:

+ +
+Input: "abbaca"
+Output: "ca"
+Explanation: 
+For example, in "abbaca" we could remove "bb" since the letters are adjacent and equal, and this is the only possible move.  The result of this move is that the string is "aaca", of which only "aa" is possible, so the final string is "ca".
+
+ +

 

+ +

Note:

+ +
    +
  1. 1 <= S.length <= 20000
  2. +
  3. S consists only of English lowercase letters.
  4. +