Skip to content

A: new #776

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
Apr 6, 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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1406">1406</span> | [Stone Game III](https://leetcode.com/problems/stone-game-iii "石子游戏 III") | [Go](problems/stone-game-iii) | Hard |
| <span id="1405">1405</span> | [Longest Happy String](https://leetcode.com/problems/longest-happy-string "最长快乐字符串") | [Go](problems/longest-happy-string) | Medium |
| <span id="1404">1404</span> | [Number of Steps to Reduce a Number in Binary Representation to One](https://leetcode.com/problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one "将二进制表示减到 1 的步骤数") | [Go](problems/number-of-steps-to-reduce-a-number-in-binary-representation-to-one) | Medium |
| <span id="1403">1403</span> | [Minimum Subsequence in Non-Increasing Order](https://leetcode.com/problems/minimum-subsequence-in-non-increasing-order "非递增顺序的最小子序列") | [Go](problems/minimum-subsequence-in-non-increasing-order) | Easy |
| <span id="1402">1402</span> | [Reducing Dishes](https://leetcode.com/problems/reducing-dishes "做菜顺序") | [Go](problems/reducing-dishes) | Hard |
| <span id="1401">1401</span> | [Circle and Rectangle Overlapping](https://leetcode.com/problems/circle-and-rectangle-overlapping "圆和矩形是否有重叠") | [Go](problems/circle-and-rectangle-overlapping) | Medium |
| <span id="1400">1400</span> | [Construct K Palindrome Strings](https://leetcode.com/problems/construct-k-palindrome-strings "构造 K 个回文字符串") | [Go](problems/construct-k-palindrome-strings) | Medium |
| <span id="1399">1399</span> | [Count Largest Group](https://leetcode.com/problems/count-largest-group "统计最大组的数目") | [Go](problems/count-largest-group) | Easy |
| <span id="1398">1398</span> | [Customers Who Bought Products A and B but Not C](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c) 🔒 | [MySQL](problems/customers-who-bought-products-a-and-b-but-not-c) | Medium |
| <span id="1397">1397</span> | [Find All Good Strings](https://leetcode.com/problems/find-all-good-strings "找到所有好字符串") | [Go](problems/find-all-good-strings) | Hard |
| <span id="1396">1396</span> | [Design Underground System](https://leetcode.com/problems/design-underground-system "设计地铁系统") | [Go](problems/design-underground-system) | Medium |
| <span id="1395">1395</span> | [Count Number of Teams](https://leetcode.com/problems/count-number-of-teams "统计作战单位数") | [Go](problems/count-number-of-teams) | Medium |
| <span id="1394">1394</span> | [Find Lucky Integer in an Array](https://leetcode.com/problems/find-lucky-integer-in-an-array "找出数组中的幸运数") | [Go](problems/find-lucky-integer-in-an-array) | Easy |
| <span id="1393">1393</span> | [Capital Gain/Loss](https://leetcode.com/problems/capital-gainloss) 🔒 | [MySQL](problems/capital-gainloss) | Medium |
| <span id="1393">1393</span> | [Capital Gain/Loss](https://leetcode.com/problems/capital-gainloss "股票的资本损益") 🔒 | [MySQL](problems/capital-gainloss) | Medium |
| <span id="1392">1392</span> | [Longest Happy Prefix](https://leetcode.com/problems/longest-happy-prefix "最长快乐前缀") | [Go](problems/longest-happy-prefix) | Hard |
| <span id="1391">1391</span> | [Check if There is a Valid Path in a Grid](https://leetcode.com/problems/check-if-there-is-a-valid-path-in-a-grid "检查网格中是否存在有效路径") | [Go](problems/check-if-there-is-a-valid-path-in-a-grid) | Medium |
| <span id="1390">1390</span> | [Four Divisors](https://leetcode.com/problems/four-divisors "四因数") | [Go](problems/four-divisors) | Medium |
Expand Down
9 changes: 9 additions & 0 deletions problems/add-binary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
<strong>Input:</strong> a = &quot;1010&quot;, b = &quot;1011&quot;
<strong>Output:</strong> &quot;10101&quot;</pre>

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

<ul>
<li>Each string consists only of <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code> characters.</li>
<li><code>1 &lt;= a.length, b.length &lt;= 10^4</code></li>
<li>Each string is either <code>&quot;0&quot;</code> or doesn&#39;t contain any leading zero.</li>
</ul>

### Related Topics
[[Math](../../tag/math/README.md)]
[[String](../../tag/string/README.md)]
Expand Down
2 changes: 1 addition & 1 deletion problems/capital-gainloss/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

[Next >](../find-lucky-integer-in-an-array "Find Lucky Integer in an Array")

## [1393. Capital Gain/Loss (Medium)](https://leetcode.com/problems/capital-gainloss "")
## [1393. Capital Gain/Loss (Medium)](https://leetcode.com/problems/capital-gainloss "股票的资本损益")


73 changes: 73 additions & 0 deletions problems/circle-and-rectangle-overlapping/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!--|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](../construct-k-palindrome-strings "Construct K Palindrome Strings")

[Next >](../reducing-dishes "Reducing Dishes")

## [1401. Circle and Rectangle Overlapping (Medium)](https://leetcode.com/problems/circle-and-rectangle-overlapping "圆和矩形是否有重叠")

<p>Given a circle represented as (<code>radius</code>, <code>x_center</code>, <code>y_center</code>)&nbsp;and an axis-aligned rectangle represented as (<code>x1</code>, <code>y1</code>, <code>x2</code>, <code>y2</code>),&nbsp;where (<code>x1</code>, <code>y1</code>) are the coordinates of the bottom-left corner, and (<code>x2</code>, <code>y2</code>) are the coordinates of the top-right corner of the&nbsp;rectangle.</p>

<p>Return True if the circle and rectangle are overlapped otherwise return False.</p>

<p>In other words, check if there are <strong>any </strong>point&nbsp;(xi, yi) such that belongs to the circle and the rectangle at the same time.</p>

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

<p><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/sample_4_1728.png" style="width: 258px; height: 167px;" /></p>

<pre>
<strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
<strong>Output:</strong> true
<strong>Explanation:</strong> Circle and rectangle share the point (1,0)
</pre>

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

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/02/20/sample_2_1728.png" style="width: 150px; height: 135px;" /></strong></p>

<pre>
<strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1
<strong>Output:</strong> true
</pre>

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

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2020/03/03/sample_6_1728.png" style="width: 175px; height: 165px;" /></strong></p>

<pre>
<strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3
<strong>Output:</strong> true
</pre>

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

<pre>
<strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1
<strong>Output:</strong> false
</pre>

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

<ul>
<li><code>1 &lt;= radius &lt;= 2000</code></li>
<li><code>-10^4 &lt;= x_center, y_center, x1, y1, x2, y2 &lt;= 10^4</code></li>
<li><code>x1 &lt; x2</code></li>
<li><code>y1 &lt; y2</code></li>
</ul>

### Related Topics
[[Geometry](../../tag/geometry/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Locate the closest point of the square to the circle, you can then find the distance from this point to the center of the circle and check if this is less than or equal to the radius.
</details>
86 changes: 86 additions & 0 deletions problems/construct-k-palindrome-strings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<!--|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](../count-largest-group "Count Largest Group")

[Next >](../circle-and-rectangle-overlapping "Circle and Rectangle Overlapping")

## [1400. Construct K Palindrome Strings (Medium)](https://leetcode.com/problems/construct-k-palindrome-strings "构造 K 个回文字符串")

<p>Given a string <code>s</code> and an integer <code>k</code>. You should construct <code>k</code> non-empty <strong>palindrome</strong> strings using <strong>all the characters</strong> in <code>s</code>.</p>

<p>Return <em><strong>True</strong></em> if you can use all the characters in <code>s</code> to construct <code>k</code> palindrome strings or <em><strong>False</strong></em> otherwise.</p>

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

<pre>
<strong>Input:</strong> s = &quot;annabelle&quot;, k = 2
<strong>Output:</strong> true
<strong>Explanation:</strong> You can construct two palindromes using all characters in s.
Some possible constructions &quot;anna&quot; + &quot;elble&quot;, &quot;anbna&quot; + &quot;elle&quot;, &quot;anellena&quot; + &quot;b&quot;
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;leetcode&quot;, k = 3
<strong>Output:</strong> false
<strong>Explanation:</strong> It is impossible to construct 3 palindromes using all the characters of s.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;true&quot;, k = 4
<strong>Output:</strong> true
<strong>Explanation:</strong> The only possible solution is to put each character in a separate string.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;yzyzyzyzyzyzyzy&quot;, k = 2
<strong>Output:</strong> true
<strong>Explanation:</strong> Simply you can put all z&#39;s in one string and all y&#39;s in the other string. Both strings will be palindrome.
</pre>

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

<pre>
<strong>Input:</strong> s = &quot;cr&quot;, k = 7
<strong>Output:</strong> false
<strong>Explanation:</strong> We don&#39;t have enough characters in s to construct 7 palindromes.
</pre>

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

<ul>
<li><code>1 &lt;= s.length &lt;= 10^5</code></li>
<li>All characters in <code>s</code> are lower-case English letters.</li>
<li><code>1 &lt;= k &lt;= 10^5</code></li>
</ul>

### Related Topics
[[Greedy](../../tag/greedy/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
If the s.length < k we cannot construct k strings from s and answer is false.
</details>

<details>
<summary>Hint 2</summary>
If the number of characters that have odd counts is > k then the minimum number of palindrome strings we can construct is > k and answer is false.
</details>

<details>
<summary>Hint 3</summary>
Otherwise you can construct exactly k palindrome strings and answer is true (why ?).
</details>
64 changes: 64 additions & 0 deletions problems/count-largest-group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<!--|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](../customers-who-bought-products-a-and-b-but-not-c "Customers Who Bought Products A and B but Not C")

[Next >](../construct-k-palindrome-strings "Construct K Palindrome Strings")

## [1399. Count Largest Group (Easy)](https://leetcode.com/problems/count-largest-group "统计最大组的数目")

<p>Given an integer&nbsp;<code>n</code>.&nbsp;Each number from <code>1</code> to <code>n</code> is grouped according to the sum of its digits.&nbsp;</p>

<p>Return&nbsp;how many groups have the largest size.</p>

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

<pre>
<strong>Input:</strong> n = 13
<strong>Output:</strong> 4
<strong>Explanation:</strong> There are 9 groups in total, they are grouped according sum of its digits of numbers from 1 to 13:
[1,10], [2,11], [3,12], [4,13], [5], [6], [7], [8], [9]. There are 4 groups with largest size.
</pre>

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

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 groups [1], [2] of size 1.
</pre>

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

<pre>
<strong>Input:</strong> n = 15
<strong>Output:</strong> 6
</pre>

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

<pre>
<strong>Input:</strong> n = 24
<strong>Output:</strong> 5
</pre>

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

<ul>
<li><code>1 &lt;= n &lt;= 10^4</code></li>
</ul>

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

### Hints
<details>
<summary>Hint 1</summary>
Count the digit sum for each integer in the range and find out the largest groups.
</details>
14 changes: 14 additions & 0 deletions problems/customers-who-bought-products-a-and-b-but-not-c/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](../find-all-good-strings "Find All Good Strings")

[Next >](../count-largest-group "Count Largest Group")

## [1398. Customers Who Bought Products A and B but Not C (Medium)](https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c "")


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Create table If Not Exists Customers (customer_id int, customer_name varchar(30));
Create table If Not Exists Orders (order_id int, customer_id int, product_name varchar(30));
Truncate table Customers;
insert into Customers (customer_id, customer_name) values ('1', 'Daniel');
insert into Customers (customer_id, customer_name) values ('2', 'Diana');
insert into Customers (customer_id, customer_name) values ('3', 'Elizabeth');
insert into Customers (customer_id, customer_name) values ('4', 'Jhon');
Truncate table Orders;
insert into Orders (order_id, customer_id, product_name) values ('10', '1', 'A');
insert into Orders (order_id, customer_id, product_name) values ('20', '1', 'B');
insert into Orders (order_id, customer_id, product_name) values ('30', '1', 'D');
insert into Orders (order_id, customer_id, product_name) values ('40', '1', 'C');
insert into Orders (order_id, customer_id, product_name) values ('50', '2', 'A');
insert into Orders (order_id, customer_id, product_name) values ('60', '3', 'A');
insert into Orders (order_id, customer_id, product_name) values ('70', '3', 'B');
insert into Orders (order_id, customer_id, product_name) values ('80', '3', 'D');
insert into Orders (order_id, customer_id, product_name) values ('90', '4', 'C');
36 changes: 30 additions & 6 deletions problems/design-underground-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@

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

<pre>
<strong>Input</strong>
[&quot;UndergroundSystem&quot;,&quot;checkIn&quot;,&quot;checkIn&quot;,&quot;checkIn&quot;,&quot;checkOut&quot;,&quot;checkOut&quot;,&quot;checkOut&quot;,&quot;getAverageTime&quot;,&quot;getAverageTime&quot;,&quot;checkIn&quot;,&quot;getAverageTime&quot;,&quot;checkOut&quot;,&quot;getAverageTime&quot;]
[[],[45,&quot;Leyton&quot;,3],[32,&quot;Paradise&quot;,8],[27,&quot;Leyton&quot;,10],[45,&quot;Waterloo&quot;,15],[27,&quot;Waterloo&quot;,20],[32,&quot;Cambridge&quot;,22],[&quot;Paradise&quot;,&quot;Cambridge&quot;],[&quot;Leyton&quot;,&quot;Waterloo&quot;],[10,&quot;Leyton&quot;,24],[&quot;Leyton&quot;,&quot;Waterloo&quot;],[10,&quot;Waterloo&quot;,38],[&quot;Leyton&quot;,&quot;Waterloo&quot;]]

<strong>Output</strong>
[null,null,null,null,null,null,null,14.0,11.0,null,11.0,null,12.0]
[null,null,null,null,null,null,null,14.00000,11.00000,null,11.00000,null,12.00000]

<strong>Explanation</strong>
UndergroundSystem undergroundSystem = new UndergroundSystem();
Expand All @@ -55,12 +55,36 @@ undergroundSystem.checkIn(27, &quot;Leyton&quot;, 10);
undergroundSystem.checkOut(45, &quot;Waterloo&quot;, 15);
undergroundSystem.checkOut(27, &quot;Waterloo&quot;, 20);
undergroundSystem.checkOut(32, &quot;Cambridge&quot;, 22);
undergroundSystem.getAverageTime(&quot;Paradise&quot;, &quot;Cambridge&quot;); // return 14.0. There was only one travel from &quot;Paradise&quot; (at time 8) to &quot;Cambridge&quot; (at time 22)
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); // return 11.0. There were two travels from &quot;Leyton&quot; to &quot;Waterloo&quot;, a customer with id=45 from time=3 to time=15 and a customer with id=27 from time=10 to time=20. So the average time is ( (15-3) + (20-10) ) / 2 = 11.0
undergroundSystem.getAverageTime(&quot;Paradise&quot;, &quot;Cambridge&quot;); &nbsp; &nbsp; &nbsp; // return 14.00000. There was only one travel from &quot;Paradise&quot; (at time 8) to &quot;Cambridge&quot; (at time 22)
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return 11.00000. There were two travels from &quot;Leyton&quot; to &quot;Waterloo&quot;, a customer with id=45 from time=3 to time=15 and a customer with id=27 from time=10 to time=20. So the average time is ( (15-3) + (20-10) ) / 2 = 11.00000
undergroundSystem.checkIn(10, &quot;Leyton&quot;, 24);
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); // return 11.0
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return 11.00000
undergroundSystem.checkOut(10, &quot;Waterloo&quot;, 38);
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); // return 12.0</pre>
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Waterloo&quot;); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// return 12.00000
</pre>

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

<pre>
[&quot;UndergroundSystem&quot;,&quot;checkIn&quot;,&quot;checkOut&quot;,&quot;getAverageTime&quot;,&quot;checkIn&quot;,&quot;checkOut&quot;,&quot;getAverageTime&quot;,&quot;checkIn&quot;,&quot;checkOut&quot;,&quot;getAverageTime&quot;]
[[],[10,&quot;Leyton&quot;,3],[10,&quot;Paradise&quot;,8],[&quot;Leyton&quot;,&quot;Paradise&quot;],[5,&quot;Leyton&quot;,10],[5,&quot;Paradise&quot;,16],[&quot;Leyton&quot;,&quot;Paradise&quot;],[2,&quot;Leyton&quot;,21],[2,&quot;Paradise&quot;,30],[&quot;Leyton&quot;,&quot;Paradise&quot;]]

<strong>Output</strong>
[null,null,null,5.00000,null,null,5.50000,null,null,6.66667]

<strong>Explanation</strong>
UndergroundSystem undergroundSystem = new UndergroundSystem();
undergroundSystem.checkIn(10, &quot;Leyton&quot;, 3);
undergroundSystem.checkOut(10, &quot;Paradise&quot;, 8);
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Paradise&quot;); // return 5.00000
undergroundSystem.checkIn(5, &quot;Leyton&quot;, 10);
undergroundSystem.checkOut(5, &quot;Paradise&quot;, 16);
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Paradise&quot;); // return 5.50000
undergroundSystem.checkIn(2, &quot;Leyton&quot;, 21);
undergroundSystem.checkOut(2, &quot;Paradise&quot;, 30);
undergroundSystem.getAverageTime(&quot;Leyton&quot;, &quot;Paradise&quot;); // return 6.66667
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
Expand Down
Loading