Skip to content

Add: new #632

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
Sep 9, 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
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1187">1187</span> | [Make Array Strictly Increasing](https://leetcode.com/problems/make-array-strictly-increasing "使数组严格递增") | [Go](https://github.com/openset/leetcode/tree/master/problems/make-array-strictly-increasing) | Hard |
| <span id="1186">1186</span> | [Maximum Subarray Sum with One Deletion](https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion "删除一次得到子数组最大和") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-subarray-sum-with-one-deletion) | Medium |
| <span id="1185">1185</span> | [Day of the Week](https://leetcode.com/problems/day-of-the-week "一周中的第几天") | [Go](https://github.com/openset/leetcode/tree/master/problems/day-of-the-week) | Easy |
| <span id="1184">1184</span> | [Distance Between Bus Stops](https://leetcode.com/problems/distance-between-bus-stops "公交站间的距离") | [Go](https://github.com/openset/leetcode/tree/master/problems/distance-between-bus-stops) | Easy |
| <span id="1183">1183</span> | [Maximum Number of Ones](https://leetcode.com/problems/maximum-number-of-ones "矩阵中 1 的最大数量") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-number-of-ones) | Hard |
| <span id="1182">1182</span> | [Shortest Distance to Target Color](https://leetcode.com/problems/shortest-distance-to-target-color "与目标颜色间的最短距离") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-to-target-color) | Medium |
| <span id="1181">1181</span> | [Before and After Puzzle](https://leetcode.com/problems/before-and-after-puzzle "前后拼接") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/before-and-after-puzzle) | Medium |
| <span id="1180">1180</span> | [Count Substrings with Only One Distinct Letter](https://leetcode.com/problems/count-substrings-with-only-one-distinct-letter "统计只含单一字母的子串") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/count-substrings-with-only-one-distinct-letter) | Easy |
| <span id="1179">1179</span> | [Reformat Department Table](https://leetcode.com/problems/reformat-department-table) | [MySQL](https://github.com/openset/leetcode/tree/master/problems/reformat-department-table) | Easy |
| <span id="1178">1178</span> | [Number of Valid Words for Each Puzzle](https://leetcode.com/problems/number-of-valid-words-for-each-puzzle "猜字谜") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle) | Hard |
| <span id="1177">1177</span> | [Can Make Palindrome from Substring](https://leetcode.com/problems/can-make-palindrome-from-substring "构建回文串检测") | [Go](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring) | Medium |
| <span id="1176">1176</span> | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") | [Go](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | Easy |
| <span id="1176">1176</span> | [Diet Plan Performance](https://leetcode.com/problems/diet-plan-performance "健身计划评估") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/diet-plan-performance) | Easy |
| <span id="1175">1175</span> | [Prime Arrangements](https://leetcode.com/problems/prime-arrangements "质数排列") | [Go](https://github.com/openset/leetcode/tree/master/problems/prime-arrangements) | Easy |
| <span id="1174">1174</span> | [Immediate Food Delivery II](https://leetcode.com/problems/immediate-food-delivery-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-ii) | Medium |
| <span id="1173">1173</span> | [Immediate Food Delivery I](https://leetcode.com/problems/immediate-food-delivery-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/immediate-food-delivery-i) | Easy |
Expand Down Expand Up @@ -157,14 +166,14 @@ LeetCode Problems' Solutions
| <span id="1078">1078</span> | [Occurrences After Bigram](https://leetcode.com/problems/occurrences-after-bigram "Bigram 分词") | [Go](https://github.com/openset/leetcode/tree/master/problems/occurrences-after-bigram) | Easy |
| <span id="1077">1077</span> | [Project Employees III](https://leetcode.com/problems/project-employees-iii "项目员工 III") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-iii) | Medium |
| <span id="1076">1076</span> | [Project Employees II](https://leetcode.com/problems/project-employees-ii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-ii) | Easy |
| <span id="1075">1075</span> | [Project Employees I](https://leetcode.com/problems/project-employees-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-i) | Easy |
| <span id="1075">1075</span> | [Project Employees I](https://leetcode.com/problems/project-employees-i "项目员工 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/project-employees-i) | Easy |
| <span id="1074">1074</span> | [Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target "元素和为目标值的子矩阵数量") | [Go](https://github.com/openset/leetcode/tree/master/problems/number-of-submatrices-that-sum-to-target) | Hard |
| <span id="1073">1073</span> | [Adding Two Negabinary Numbers](https://leetcode.com/problems/adding-two-negabinary-numbers "负二进制数相加") | [Go](https://github.com/openset/leetcode/tree/master/problems/adding-two-negabinary-numbers) | Medium |
| <span id="1072">1072</span> | [Flip Columns For Maximum Number of Equal Rows](https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows "按列翻转得到最大值等行数") | [Go](https://github.com/openset/leetcode/tree/master/problems/flip-columns-for-maximum-number-of-equal-rows) | Medium |
| <span id="1071">1071</span> | [Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings "字符串的最大公因子") | [Go](https://github.com/openset/leetcode/tree/master/problems/greatest-common-divisor-of-strings) | Easy |
| <span id="1070">1070</span> | [Product Sales Analysis III](https://leetcode.com/problems/product-sales-analysis-iii) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-iii) | Medium |
| <span id="1069">1069</span> | [Product Sales Analysis II](https://leetcode.com/problems/product-sales-analysis-ii "产品销售分析 II") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-ii) | Easy |
| <span id="1068">1068</span> | [Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-i) | Easy |
| <span id="1068">1068</span> | [Product Sales Analysis I](https://leetcode.com/problems/product-sales-analysis-i "产品销售分析 I") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/product-sales-analysis-i) | Easy |
| <span id="1067">1067</span> | [Digit Count in Range](https://leetcode.com/problems/digit-count-in-range "范围内的数字计数") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/digit-count-in-range) | Hard |
| <span id="1066">1066</span> | [Campus Bikes II](https://leetcode.com/problems/campus-bikes-ii "校园自行车分配 II") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/campus-bikes-ii) | Medium |
| <span id="1065">1065</span> | [Index Pairs of a String](https://leetcode.com/problems/index-pairs-of-a-string "字符串的索引对") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/index-pairs-of-a-string) | Easy |
Expand Down Expand Up @@ -295,7 +304,7 @@ LeetCode Problems' Solutions
| <span id="940">940</span> | [Distinct Subsequences II](https://leetcode.com/problems/distinct-subsequences-ii "不同的子序列 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/distinct-subsequences-ii) | Hard |
| <span id="939">939</span> | [Minimum Area Rectangle](https://leetcode.com/problems/minimum-area-rectangle "最小面积矩形") | [Go](https://github.com/openset/leetcode/tree/master/problems/minimum-area-rectangle) | Medium |
| <span id="938">938</span> | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst "二叉搜索树的范围和") | [Go](https://github.com/openset/leetcode/tree/master/problems/range-sum-of-bst) | Easy |
| <span id="937">937</span> | [Reorder Log Files](https://leetcode.com/problems/reorder-log-files "重新排列日志文件") | [Go](https://github.com/openset/leetcode/tree/master/problems/reorder-log-files) | Easy |
| <span id="937">937</span> | [Reorder Data in Log Files](https://leetcode.com/problems/reorder-data-in-log-files "重新排列日志文件") | [Go](https://github.com/openset/leetcode/tree/master/problems/reorder-data-in-log-files) | Easy |
| <span id="936">936</span> | [Stamping The Sequence](https://leetcode.com/problems/stamping-the-sequence "戳印序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/stamping-the-sequence) | Hard |
| <span id="935">935</span> | [Knight Dialer](https://leetcode.com/problems/knight-dialer "骑士拨号器") | [Go](https://github.com/openset/leetcode/tree/master/problems/knight-dialer) | Medium |
| <span id="934">934</span> | [Shortest Bridge](https://leetcode.com/problems/shortest-bridge "最短的桥") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-bridge) | Medium |
Expand Down
28 changes: 28 additions & 0 deletions problems/before-and-after-puzzle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!--|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/count-substrings-with-only-one-distinct-letter "Count Substrings with Only One Distinct Letter")

[Next >](https://github.com/openset/leetcode/tree/master/problems/shortest-distance-to-target-color "Shortest Distance to Target Color")

## 1181. Before and After Puzzle (Medium)



### Related Topics
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
What if you check every pair of strings (bruteforce)?
</details>

<details>
<summary>Hint 2</summary>
For every two strings, check if they can form a puzzle by comparing their last and first words.
</details>
2 changes: 1 addition & 1 deletion problems/best-time-to-buy-and-sell-stock-ii/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<strong>Explanation:</strong> In this case, no transaction is done, i.e. max profit = 0.</pre>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

### Similar Questions
1. [Best Time to Buy and Sell Stock](https://github.com/openset/leetcode/tree/master/problems/best-time-to-buy-and-sell-stock) (Easy)
Expand Down
2 changes: 1 addition & 1 deletion problems/can-make-palindrome-from-substring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Next >](https://github.com/openset/leetcode/tree/master/problems/number-of-valid-words-for-each-puzzle "Number of Valid Words for Each Puzzle")

## 5175. Can Make Palindrome from Substring (Medium)
## 1177. Can Make Palindrome from Substring (Medium)

<p>Given a string <code>s</code>, we make queries on substrings of <code>s</code>.</p>

Expand Down
34 changes: 34 additions & 0 deletions problems/count-substrings-with-only-one-distinct-letter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!--|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/reformat-department-table "Reformat Department Table")

[Next >](https://github.com/openset/leetcode/tree/master/problems/before-and-after-puzzle "Before and After Puzzle")

## 1180. Count Substrings with Only One Distinct Letter (Easy)



### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
[[String](https://github.com/openset/leetcode/tree/master/tag/string/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
What if we divide the string into substrings containing only one distinct character with maximal lengths?
</details>

<details>
<summary>Hint 2</summary>
Now that you have sub-strings with only one distinct character, Try to come up with a formula that counts the number of its sub-strings.
</details>

<details>
<summary>Hint 3</summary>
Alternatively, Observe that the constraints are small so you can use brute force.
</details>
66 changes: 66 additions & 0 deletions problems/day-of-the-week/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--|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/distance-between-bus-stops "Distance Between Bus Stops")

[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-subarray-sum-with-one-deletion "Maximum Subarray Sum with One Deletion")

## 1185. Day of the Week (Easy)

<p>Given a date, return the corresponding day of the week for that date.</p>

<p>The input is given as three integers representing the <code>day</code>, <code>month</code> and <code>year</code> respectively.</p>

<p>Return the answer as one of the following values&nbsp;<code>{&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;}</code>.</p>

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

<pre>
<strong>Input:</strong> day = 31, month = 8, year = 2019
<strong>Output:</strong> &quot;Saturday&quot;
</pre>

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

<pre>
<strong>Input:</strong> day = 18, month = 7, year = 1999
<strong>Output:</strong> &quot;Sunday&quot;
</pre>

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

<pre>
<strong>Input:</strong> day = 15, month = 8, year = 1993
<strong>Output:</strong> &quot;Sunday&quot;
</pre>

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

<ul>
<li>The given dates are valid&nbsp;dates between the years <code>1971</code> and <code>2100</code>.</li>
</ul>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Sum up the number of days for the years before the given year.
</details>

<details>
<summary>Hint 2</summary>
Handle the case of a leap year.
</details>

<details>
<summary>Hint 3</summary>
Find the number of days for each month of the given year.
</details>
4 changes: 2 additions & 2 deletions problems/diet-plan-performance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

[Next >](https://github.com/openset/leetcode/tree/master/problems/can-make-palindrome-from-substring "Can Make Palindrome from Substring")

## 5174. Diet Plan Performance (Easy)
## 1176. Diet Plan Performance (Easy)

<p>A dieter consumes&nbsp;<code>calories[i]</code>&nbsp;calories on the <code>i</code>-th day.&nbsp; For every consecutive sequence of <code>k</code> days, they look at <em>T</em>, the total calories consumed during that sequence of <code>k</code> days:</p>

Expand Down Expand Up @@ -44,7 +44,7 @@
<pre>
<strong>Input:</strong> calories = [6,5,0,0], k = 2, lower = 1, upper = 5
<strong>Output:</strong> 0
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, calories[2] + calories[3] &lt; lower, total points = 0.
<strong>Explaination</strong>: calories[0] + calories[1] &gt; upper, lower &lt;= calories[1] + calories[2] &lt;= upper, calories[2] + calories[3] &lt; lower, total points = 0.
</pre>

<p>&nbsp;</p>
Expand Down
71 changes: 71 additions & 0 deletions problems/distance-between-bus-stops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!--|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/maximum-number-of-ones "Maximum Number of Ones")

[Next >](https://github.com/openset/leetcode/tree/master/problems/day-of-the-week "Day of the Week")

## 1184. Distance Between Bus Stops (Easy)

<p>A bus&nbsp;has <code>n</code> stops numbered from <code>0</code> to <code>n - 1</code> that form&nbsp;a circle. We know the distance between all pairs of neighboring stops where <code>distance[i]</code> is the distance between the stops number&nbsp;<code>i</code> and <code>(i + 1) % n</code>.</p>

<p>The bus goes along both directions&nbsp;i.e. clockwise and counterclockwise.</p>

<p>Return the shortest distance between the given&nbsp;<code>start</code>&nbsp;and <code>destination</code>&nbsp;stops.</p>

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

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1.jpg" style="width: 388px; height: 240px;" /></p>

<pre>
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 1
<strong>Output:</strong> 1
<strong>Explanation:</strong> Distance between 0 and 1 is 1 or 9, minimum is 1.</pre>

<p>&nbsp;</p>

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

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-1.jpg" style="width: 388px; height: 240px;" /></p>

<pre>
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 2
<strong>Output:</strong> 3
<strong>Explanation:</strong> Distance between 0 and 2 is 3 or 7, minimum is 3.
</pre>

<p>&nbsp;</p>

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

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-2.jpg" style="width: 388px; height: 240px;" /></p>

<pre>
<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> Distance between 0 and 3 is 6 or 4, minimum is 4.
</pre>

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

<ul>
<li><code>1 &lt;= n&nbsp;&lt;= 10^4</code></li>
<li><code>distance.length == n</code></li>
<li><code>0 &lt;= start, destination &lt; n</code></li>
<li><code>0 &lt;= distance[i] &lt;= 10^4</code></li>
</ul>

### Related Topics
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Find the distance between the two stops if the bus moved in clockwise or counterclockwise directions.
</details>
Loading