Skip to content

Add: new #691

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
Oct 22, 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: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1225">1225</span> | [Report Contiguous Dates](https://leetcode.com/problems/report-contiguous-dates) | [MySQL](https://github.com/openset/leetcode/tree/master/problems/report-contiguous-dates) | Hard |
| <span id="1236">1236</span> | [Web Crawler](https://leetcode.com/problems/web-crawler) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/web-crawler) | Medium |
| <span id="1235">1235</span> | [Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling "规划兼职工作") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-profit-in-job-scheduling) | Hard |
| <span id="1234">1234</span> | [Replace the Substring for Balanced String](https://leetcode.com/problems/replace-the-substring-for-balanced-string "替换子串得到平衡字符串") | [Go](https://github.com/openset/leetcode/tree/master/problems/replace-the-substring-for-balanced-string) | Medium |
| <span id="1233">1233</span> | [Remove Sub-Folders from the Filesystem](https://leetcode.com/problems/remove-sub-folders-from-the-filesystem "删除子文件夹") | [Go](https://github.com/openset/leetcode/tree/master/problems/remove-sub-folders-from-the-filesystem) | Medium |
| <span id="1232">1232</span> | [Check If It Is a Straight Line](https://leetcode.com/problems/check-if-it-is-a-straight-line "缀点成线") | [Go](https://github.com/openset/leetcode/tree/master/problems/check-if-it-is-a-straight-line) | Easy |
| <span id="1231">1231</span> | [Divide Chocolate](https://leetcode.com/problems/divide-chocolate "分享巧克力") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/divide-chocolate) | Hard |
| <span id="1230">1230</span> | [Toss Strange Coins](https://leetcode.com/problems/toss-strange-coins "抛掷硬币") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/toss-strange-coins) | Medium |
| <span id="1229">1229</span> | [Meeting Scheduler](https://leetcode.com/problems/meeting-scheduler "安排会议日程") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/meeting-scheduler) | Medium |
| <span id="1228">1228</span> | [Missing Number In Arithmetic Progression](https://leetcode.com/problems/missing-number-in-arithmetic-progression "等差数列中缺失的数字") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/missing-number-in-arithmetic-progression) | Easy |
| <span id="1227">1227</span> | [Airplane Seat Assignment Probability](https://leetcode.com/problems/airplane-seat-assignment-probability) | [Go](https://github.com/openset/leetcode/tree/master/problems/airplane-seat-assignment-probability) | Medium |
| <span id="1226">1226</span> | [The Dining Philosophers](https://leetcode.com/problems/the-dining-philosophers) | [Go](https://github.com/openset/leetcode/tree/master/problems/the-dining-philosophers) | Medium |
| <span id="1225">1225</span> | [Report Contiguous Dates](https://leetcode.com/problems/report-contiguous-dates) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/report-contiguous-dates) | Hard |
| <span id="1224">1224</span> | [Maximum Equal Frequency](https://leetcode.com/problems/maximum-equal-frequency "最大相等频率") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-equal-frequency) | Hard |
| <span id="1223">1223</span> | [Dice Roll Simulation](https://leetcode.com/problems/dice-roll-simulation "掷骰子模拟") | [Go](https://github.com/openset/leetcode/tree/master/problems/dice-roll-simulation) | Medium |
| <span id="1222">1222</span> | [Queens That Can Attack the King](https://leetcode.com/problems/queens-that-can-attack-the-king "可以攻击国王的皇后") | [Go](https://github.com/openset/leetcode/tree/master/problems/queens-that-can-attack-the-king) | Medium |
Expand Down Expand Up @@ -99,7 +110,7 @@ LeetCode Problems' Solutions
| <span id="1191">1191</span> | [K-Concatenation Maximum Sum](https://leetcode.com/problems/k-concatenation-maximum-sum "K 次串联后最大子数组之和") | [Go](https://github.com/openset/leetcode/tree/master/problems/k-concatenation-maximum-sum) | Medium |
| <span id="1190">1190</span> | [Reverse Substrings Between Each Pair of Parentheses](https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses "反转每对括号间的子串") | [Go](https://github.com/openset/leetcode/tree/master/problems/reverse-substrings-between-each-pair-of-parentheses) | Medium |
| <span id="1189">1189</span> | [Maximum Number of Balloons](https://leetcode.com/problems/maximum-number-of-balloons "“气球” 的最大数量") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-number-of-balloons) | Easy |
| <span id="1188">1188</span> | [Design Bounded Blocking Queue](https://leetcode.com/problems/design-bounded-blocking-queue) 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-bounded-blocking-queue) | Medium |
| <span id="1188">1188</span> | [Design Bounded Blocking Queue](https://leetcode.com/problems/design-bounded-blocking-queue "设计有限阻塞队列") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-bounded-blocking-queue) | Medium |
| <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 |
Expand Down Expand Up @@ -180,7 +191,7 @@ LeetCode Problems' Solutions
| <span id="1110">1110</span> | [Delete Nodes And Return Forest](https://leetcode.com/problems/delete-nodes-and-return-forest "删点成林") | [Go](https://github.com/openset/leetcode/tree/master/problems/delete-nodes-and-return-forest) | Medium |
| <span id="1109">1109</span> | [Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings "航班预订统计") | [Go](https://github.com/openset/leetcode/tree/master/problems/corporate-flight-bookings) | Medium |
| <span id="1108">1108</span> | [Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address "IP 地址无效化") | [Go](https://github.com/openset/leetcode/tree/master/problems/defanging-an-ip-address) | Easy |
| <span id="1107">1107</span> | [New Users Daily Count](https://leetcode.com/problems/new-users-daily-count) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/new-users-daily-count) | Medium |
| <span id="1107">1107</span> | [New Users Daily Count](https://leetcode.com/problems/new-users-daily-count "每日新用户统计") 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/new-users-daily-count) | Medium |
| <span id="1106">1106</span> | [Parsing A Boolean Expression](https://leetcode.com/problems/parsing-a-boolean-expression "解析布尔表达式") | [Go](https://github.com/openset/leetcode/tree/master/problems/parsing-a-boolean-expression) | Hard |
| <span id="1105">1105</span> | [Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves "填充书架") | [Go](https://github.com/openset/leetcode/tree/master/problems/filling-bookcase-shelves) | Medium |
| <span id="1104">1104</span> | [Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree "二叉树寻路") | [Go](https://github.com/openset/leetcode/tree/master/problems/path-in-zigzag-labelled-binary-tree) | Medium |
Expand Down
60 changes: 60 additions & 0 deletions problems/airplane-seat-assignment-probability/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](https://github.com/openset/leetcode/tree/master/problems/the-dining-philosophers "The Dining Philosophers")

[Next >](https://github.com/openset/leetcode/tree/master/problems/missing-number-in-arithmetic-progression "Missing Number In Arithmetic Progression")

## [1227. Airplane Seat Assignment Probability (Medium)](https://leetcode.com/problems/airplane-seat-assignment-probability "")

<p><code data-stringify-type="code">n</code>&nbsp;passengers board an airplane with exactly&nbsp;<code data-stringify-type="code">n</code>&nbsp;seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of passengers will:</p>

<ul>
<li>Take their own seat if it is still available,&nbsp;</li>
<li>Pick other seats randomly when they find their seat occupied&nbsp;</li>
</ul>

<p>What is the probability that the n-th person can get his own seat?</p>

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

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 1.00000
<strong>Explanation: </strong>The first person can only get the first seat.</pre>

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

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 0.50000
<strong>Explanation: </strong>The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).
</pre>

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

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

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
[[Brainteaser](https://github.com/openset/leetcode/tree/master/tag/brainteaser/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Use dynamic programming, dp[i] indicates the probability that the i-th person can get his seat when there're i persons in total. It's okay to start with O(n^2) solution and then optimize it.
</details>

<details>
<summary>Hint 2</summary>
Try to find the regular pattern of the result.
</details>
66 changes: 66 additions & 0 deletions problems/check-if-it-is-a-straight-line/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 <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/divide-chocolate "Divide Chocolate")

[Next >](https://github.com/openset/leetcode/tree/master/problems/remove-sub-folders-from-the-filesystem "Remove Sub-Folders from the Filesystem")

## [1232. Check If It Is a Straight Line (Easy)](https://leetcode.com/problems/check-if-it-is-a-straight-line "缀点成线")

<p>You are given an array&nbsp;<code>coordinates</code>, <code>coordinates[i] = [x, y]</code>, where <code>[x, y]</code> represents the coordinate of a point. Check if these points&nbsp;make a straight line in the XY plane.</p>

<p>&nbsp;</p>

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

<p><img alt="" src="https://assets.leetcode.com/uploads/2019/10/15/untitled-diagram-2.jpg" style="width: 336px; height: 336px;" /></p>

<pre>
<strong>Input:</strong> coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]
<strong>Output:</strong> true
</pre>

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

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

<pre>
<strong>Input:</strong> coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]
<strong>Output:</strong> false
</pre>

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

<ul>
<li><code>2 &lt;=&nbsp;coordinates.length &lt;= 1000</code></li>
<li><code>coordinates[i].length == 2</code></li>
<li><code>-10^4 &lt;=&nbsp;coordinates[i][0],&nbsp;coordinates[i][1] &lt;= 10^4</code></li>
<li><code>coordinates</code>&nbsp;contains no duplicate point.</li>
</ul>

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

### Hints
<details>
<summary>Hint 1</summary>
If there're only 2 points, return true.
</details>

<details>
<summary>Hint 2</summary>
Check if all other points lie on the line defined by the first 2 points.
</details>

<details>
<summary>Hint 3</summary>
Use cross product to check collinearity.
</details>
2 changes: 1 addition & 1 deletion problems/design-bounded-blocking-queue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

[Next >](https://github.com/openset/leetcode/tree/master/problems/maximum-number-of-balloons "Maximum Number of Balloons")

## [1188. Design Bounded Blocking Queue (Medium)](https://leetcode.com/problems/design-bounded-blocking-queue "")
## [1188. Design Bounded Blocking Queue (Medium)](https://leetcode.com/problems/design-bounded-blocking-queue "设计有限阻塞队列")


34 changes: 34 additions & 0 deletions problems/divide-chocolate/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 <openset.wang@gmail.com> |-->
<!--|@link https://github.com/openset |-->
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/toss-strange-coins "Toss Strange Coins")

[Next >](https://github.com/openset/leetcode/tree/master/problems/check-if-it-is-a-straight-line "Check If It Is a Straight Line")

## [1231. Divide Chocolate (Hard)](https://leetcode.com/problems/divide-chocolate "分享巧克力")



### Related Topics
[[Greedy](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)]
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
After dividing the array into K+1 sub-arrays, you will pick the sub-array with the minimum sum.
</details>

<details>
<summary>Hint 2</summary>
Divide the sub-array into K+1 sub-arrays such that the minimum sub-array sum is as maximum as possible.
</details>

<details>
<summary>Hint 3</summary>
Use binary search with greedy check.
</details>
81 changes: 81 additions & 0 deletions problems/maximum-profit-in-job-scheduling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!--|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](https://github.com/openset/leetcode/tree/master/problems/replace-the-substring-for-balanced-string "Replace the Substring for Balanced String")

[Next >](https://github.com/openset/leetcode/tree/master/problems/web-crawler "Web Crawler")

## [1235. Maximum Profit in Job Scheduling (Hard)](https://leetcode.com/problems/maximum-profit-in-job-scheduling "规划兼职工作")

<p>We have <code>n</code> jobs, where every job&nbsp;is scheduled to be done from <code>startTime[i]</code> to <code>endTime[i]</code>, obtaining a profit&nbsp;of <code>profit[i]</code>.</p>

<p>You&#39;re given the&nbsp;<code>startTime</code>&nbsp;,&nbsp;<code>endTime</code>&nbsp;and <code>profit</code>&nbsp;arrays,&nbsp;you need to output the maximum profit you can take such that there are no 2 jobs in the subset&nbsp;with overlapping time range.</p>

<p>If you choose a job that ends at time <code>X</code>&nbsp;you&nbsp;will be able to start another job that starts at time <code>X</code>.</p>

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

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/10/10/sample1_1584.png" style="width: 380px; height: 154px;" /></strong></p>

<pre>
<strong>Input:</strong> startTime = [1,2,3,3], endTime = [3,4,5,6], profit = [50,10,40,70]
<strong>Output:</strong> 120
<strong>Explanation:</strong> The subset chosen is the first and fourth job.
Time range [1-3]+[3-6] , we get profit of 120 = 50 + 70.
</pre>

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

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/10/10/sample22_1584.png" style="width: 600px; height: 112px;" /> </strong></p>

<pre>
<strong>
Input:</strong> startTime = [1,2,3,4,6], endTime = [3,5,10,6,9], profit = [20,20,100,70,60]
<strong>Output:</strong> 150
<strong>Explanation:</strong> The subset chosen is the first, fourth and fifth job.
Profit obtained 150 = 20 + 70 + 60.
</pre>

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

<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/10/10/sample3_1584.png" style="width: 400px; height: 112px;" /></strong></p>

<pre>
<strong>Input:</strong> startTime = [1,1,1], endTime = [2,3,4], profit = [5,6,4]
<strong>Output:</strong> 6
</pre>

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

<ul>
<li><code>1 &lt;= startTime.length == endTime.length ==&nbsp;profit.length&nbsp;&lt;= 5 * 10^4</code></li>
<li><code>1 &lt;=&nbsp;startTime[i] &lt;&nbsp;endTime[i] &lt;= 10^9</code></li>
<li><code>1 &lt;=&nbsp;profit[i] &lt;= 10^4</code></li>
</ul>

### Related Topics
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
[[Binary Search](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)]
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
Think on DP.
</details>

<details>
<summary>Hint 2</summary>
Sort the elements by starting time, then define the dp[i] as the maximum profit taking elements from the suffix starting at i.
</details>

<details>
<summary>Hint 3</summary>
Use binarySearch (lower_bound/upper_bound on C++) to get the next index for the DP transition.
</details>
Loading