Skip to content
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ LeetCode Problems' Solutions

| # | Title | Solution | Difficulty |
| :-: | - | - | :-: |
| <span id="1096">1096</span> | [Brace Expansion II](https://leetcode.com/problems/brace-expansion-ii "花括号展开 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii) | Hard |
| <span id="1095">1095</span> | [Find in Mountain Array](https://leetcode.com/problems/find-in-mountain-array "山脉数组中查找目标值") | [Go](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array) | Hard |
| <span id="1094">1094</span> | [Car Pooling](https://leetcode.com/problems/car-pooling "拼车") | [Go](https://github.com/openset/leetcode/tree/master/problems/car-pooling) | Medium |
| <span id="1093">1093</span> | [Statistics from a Large Sample](https://leetcode.com/problems/statistics-from-a-large-sample "大样本统计") | [Go](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | Medium |
| <span id="1092">1092</span> | [Shortest Common Supersequence](https://leetcode.com/problems/shortest-common-supersequence "最短公共超序列") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-common-supersequence) | Hard |
| <span id="1091">1091</span> | [Shortest Path in Binary Matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix "二进制矩阵中的最短路径") | [Go](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-binary-matrix) | Medium |
| <span id="1090">1090</span> | [Largest Values From Labels](https://leetcode.com/problems/largest-values-from-labels "受标签影响的最大值") | [Go](https://github.com/openset/leetcode/tree/master/problems/largest-values-from-labels) | Medium |
Expand Down
78 changes: 78 additions & 0 deletions problems/brace-expansion-ii/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--|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/find-in-mountain-array "Find in Mountain Array")

Next >

## 1096. Brace Expansion II (Hard)

<p>Under a grammar given below, strings can represent a set of lowercase words.&nbsp; Let&#39;s&nbsp;use <code>R(expr)</code>&nbsp;to denote the <strong>set</strong> of words the expression represents.</p>

<p>Grammar can best be understood through simple examples:</p>

<ul>
<li>Single letters represent a singleton set containing that word.
<ul>
<li><code>R(&quot;a&quot;) = {&quot;a&quot;}</code></li>
<li><code>R(&quot;w&quot;) = {&quot;w&quot;}</code></li>
</ul>
</li>
<li>When we take a comma delimited list of 2 or more expressions, we take the union of possibilities.
<ul>
<li><code>R(&quot;{a,b,c}&quot;) = {&quot;a&quot;,&quot;b&quot;,&quot;c&quot;}</code></li>
<li><code>R(&quot;{{a,b},{b,c}}&quot;) = {&quot;a&quot;,&quot;b&quot;,&quot;c&quot;}</code>&nbsp;(notice the final set only contains each word at most once)</li>
</ul>
</li>
<li>When we concatenate two expressions, we take the set of possible concatenations between two words where the first word comes from the first expression and the second word comes from the second expression.
<ul>
<li><code>R(&quot;{a,b}{c,d}&quot;) = {&quot;ac&quot;,&quot;ad&quot;,&quot;bc&quot;,&quot;bd&quot;}</code></li>
<li><code>R(&quot;{a{b,c}}{{d,e},f{g,h}}&quot;) = R(&quot;{ab,ac}{dfg,dfh,efg,efh}&quot;) = {&quot;abdfg&quot;, &quot;abdfh&quot;, &quot;abefg&quot;, &quot;abefh&quot;, &quot;acdfg&quot;, &quot;acdfh&quot;, &quot;acefg&quot;, &quot;acefh&quot;}</code></li>
</ul>
</li>
</ul>

<p>Formally, the 3 rules for our grammar:</p>

<ul>
<li>For every lowercase letter <code>x</code>, we have <code>R(x) = {x}</code></li>
<li>For expressions <code>e_1, e_2, ... , e_k</code>&nbsp;with <code>k &gt;= 2</code>, we have <code>R({e_1,e_2,...}) = R(e_1)&nbsp;&cup; R(e_2)&nbsp;&cup; ...</code></li>
<li>For&nbsp;expressions <code>e_1</code> and <code>e_2</code>, we have <code>R(e_1 + e_2) = {a + b for (a, b) in&nbsp;R(e_1)&nbsp;&times; R(e_2)}</code>, where + denotes concatenation, and &times; denotes the cartesian product.</li>
</ul>

<p>Given an <code>expression</code> representing a set of words under the given grammar, return the&nbsp;sorted list of words that the expression represents.</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong><span id="example-input-1-1">&quot;{a,b}{c{d,e}}&quot;</span>
<strong>Output: </strong><span id="example-output-1">[&quot;acd&quot;,&quot;ace&quot;,&quot;bcd&quot;,&quot;bce&quot;]</span>
</pre>

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

<pre>
<strong>Input: </strong><span>&quot;{{a,z},a{b,c},{ab,z}}&quot;</span>
<strong>Output: </strong><span>[&quot;a&quot;,&quot;ab&quot;,&quot;ac&quot;,&quot;z&quot;]</span>
<strong>Explanation: </strong>Each distinct word is written only once in the final answer.
</pre>

<p>&nbsp;</p>

<p><strong>Constraints:</strong></p>

<ol>
<li><code>1 &lt;= expression.length &lt;= 50</code></li>
<li><code>expression[i]</code> consists of <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;,&#39;</code>or lowercase English letters.</li>
<li>The given&nbsp;<code>expression</code>&nbsp;represents a set of words based on the grammar given in the description.</li>
</ol>
</div>
</div>
73 changes: 73 additions & 0 deletions problems/car-pooling/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](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample "Statistics from a Large Sample")

[Next >](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array "Find in Mountain Array")

## 1094. Car Pooling (Medium)

<p>You are driving a vehicle that&nbsp;has <code>capacity</code> empty seats initially available for passengers.&nbsp; The vehicle <strong>only</strong> drives east (ie. it <strong>cannot</strong> turn around and drive west.)</p>

<p>Given a list of <code>trips</code>, <code>trip[i] = [num_passengers, start_location, end_location]</code>&nbsp;contains information about the <code>i</code>-th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.&nbsp; The locations are given as the number of kilometers&nbsp;due east from your vehicle&#39;s initial location.</p>

<p>Return <code>true</code> if and only if&nbsp;it is possible to pick up and drop off all passengers for all the given trips.&nbsp;</p>

<p>&nbsp;</p>

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

<pre>
<strong>Input: </strong>trips = <span id="example-input-1-1">[[2,1,5],[3,3,7]]</span>, capacity = <span id="example-input-1-2">4</span>
<strong>Output: </strong><span id="example-output-1">false</span>
</pre>

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

<pre>
<strong>Input: </strong>trips = <span id="example-input-2-1">[[2,1,5],[3,3,7]]</span>, capacity = <span id="example-input-2-2">5</span>
<strong>Output: </strong><span id="example-output-2">true</span>
</pre>

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

<pre>
<strong>Input: </strong>trips = <span id="example-input-3-1">[[2,1,5],[3,5,7]]</span>, capacity = <span id="example-input-3-2">3</span>
<strong>Output: </strong><span id="example-output-3">true</span>
</pre>

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

<pre>
<strong>Input: </strong>trips = <span id="example-input-4-1">[[3,2,7],[3,7,9],[8,3,9]]</span>, capacity = <span id="example-input-4-2">11</span>
<strong>Output: </strong><span id="example-output-4">true</span>
</pre>
</div>
</div>
</div>

<div>
<div>
<div>
<div>&nbsp;</div>
</div>
</div>
</div>

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

<ol>
<li><code>trips.length &lt;= 1000</code></li>
<li><code>trips[i].length == 3</code></li>
<li><code>1 &lt;= trips[i][0] &lt;= 100</code></li>
<li><code>0 &lt;= trips[i][1] &lt; trips[i][2] &lt;= 1000</code></li>
<li><code>1 &lt;=&nbsp;capacity &lt;= 100000</code></li>
</ol>
65 changes: 65 additions & 0 deletions problems/find-in-mountain-array/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!--|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/car-pooling "Car Pooling")

[Next >](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii "Brace Expansion II")

## 1095. Find in Mountain Array (Hard)

<p><em>(This problem is an&nbsp;<strong>interactive problem</strong>.)</em></p>

<p>You may recall that an array&nbsp;<code>A</code> is a <em>mountain array</em> if and only if:</p>

<ul>
<li><code>A.length &gt;= 3</code></li>
<li>There exists some&nbsp;<code>i</code>&nbsp;with&nbsp;<code>0 &lt; i&nbsp;&lt; A.length - 1</code>&nbsp;such that:
<ul>
<li><code>A[0] &lt; A[1] &lt; ... A[i-1] &lt; A[i]</code></li>
<li><code>A[i] &gt; A[i+1] &gt; ... &gt; A[A.length - 1]</code></li>
</ul>
</li>
</ul>

<p>Given a mountain&nbsp;array <code>mountainArr</code>, return the <strong>minimum</strong>&nbsp;<code>index</code> such that <code>mountainArr.get(index) == target</code>.&nbsp; If such an <code>index</code>&nbsp;doesn&#39;t exist, return <code>-1</code>.</p>

<p><strong>You can&#39;t access the mountain array directly.</strong>&nbsp; You may only access the array using a&nbsp;<code>MountainArray</code>&nbsp;interface:</p>

<ul>
<li><code>MountainArray.get(k)</code> returns the element of the array at index <code>k</code>&nbsp;(0-indexed).</li>
<li><code>MountainArray.length()</code>&nbsp;returns the length of the array.</li>
</ul>

<p>Submissions making more than <code>100</code> calls to&nbsp;<code>MountainArray.get</code>&nbsp;will be judged <em>Wrong Answer</em>.&nbsp; Also, any solutions that attempt to circumvent the judge&nbsp;will result in disqualification.</p>

<ol>
</ol>

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

<pre>
<strong>Input:</strong> array = [1,2,3,4,5,3,1], target = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.</pre>

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

<pre>
<strong>Input:</strong> array = [0,1,2,4,2,1], target = 3
<strong>Output:</strong> -1
<strong>Explanation:</strong> 3 does not exist in <code>the array,</code> so we return -1.
</pre>

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

<ol>
<li><code>3 &lt;= mountain_arr.length() &lt;= 10000</code></li>
<li><code>0 &lt;= target &lt;= 10^9</code></li>
<li><code>0 &lt;= mountain_arr.get(index) &lt;=&nbsp;10^9</code></li>
</ol>
2 changes: 1 addition & 1 deletion problems/shortest-common-supersequence/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/shortest-path-in-binary-matrix "Shortest Path in Binary Matrix")

Next >
[Next >](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample "Statistics from a Large Sample")

## 1092. Shortest Common Supersequence (Hard)

Expand Down
51 changes: 51 additions & 0 deletions problems/statistics-from-a-large-sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--|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/shortest-common-supersequence "Shortest Common Supersequence")

[Next >](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling")

## 1093. Statistics from a Large Sample (Medium)

<p>We sampled integers between <code>0</code> and <code>255</code>, and stored the results in an array <code>count</code>:&nbsp; <code>count[k]</code> is the number of integers we sampled equal to <code>k</code>.</p>

<p>Return the minimum, maximum, mean, median, and mode of the sample respectively, as an array of <strong>floating point numbers</strong>.&nbsp; The mode is guaranteed to be unique.</p>

<p><em>(Recall that the median of a sample is:</em></p>

<ul>
<li><em>The middle element, if the elements of the sample were sorted and the number of elements is odd;</em></li>
<li><em>The average of the middle two elements, if the elements of the sample were sorted and the number of elements is even.)</em></li>
</ul>

<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre><strong>Input:</strong> count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
<strong>Output:</strong> [1.00000,3.00000,2.37500,2.50000,3.00000]
</pre><p><strong>Example 2:</strong></p>
<pre><strong>Input:</strong> count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
<strong>Output:</strong> [1.00000,4.00000,2.18182,2.00000,1.00000]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ol>
<li><code>count.length == 256</code></li>
<li><code>1 &lt;= sum(count) &lt;= 10^9</code></li>
<li>The mode of the sample that count represents is unique.</li>
<li>Answers within <code>10^-5</code> of the true value will be accepted as correct.</li>
</ol>

### Related Topics
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
[[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)]

### Hints
<details>
<summary>Hint 1</summary>
The hard part is the median. Write a helper function which finds the k-th element from the sample.
</details>
1 change: 1 addition & 0 deletions tag/math/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

| # | 题名 | 标签 | 难度 |
| :-: | - | - | :-: |
| 1093 | [大样本统计](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium |
| 1073 | [负二进制数相加](https://github.com/openset/leetcode/tree/master/problems/adding-two-negabinary-numbers) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] | Medium |
| 1067 | [范围内的数字计数](https://github.com/openset/leetcode/tree/master/problems/digit-count-in-range) 🔒 | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Hard |
| 1058 | [最小化舍入误差以满足目标](https://github.com/openset/leetcode/tree/master/problems/minimize-rounding-error-to-meet-target) 🔒 | [[贪心算法](https://github.com/openset/leetcode/tree/master/tag/greedy/README.md)] [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[动态规划](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)] | Medium |
Expand Down
1 change: 1 addition & 0 deletions tag/two-pointers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

| # | 题名 | 标签 | 难度 |
| :-: | - | - | :-: |
| 1093 | [大样本统计](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample) | [[数学](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium |
| 1004 | [最大连续1的个数 III](https://github.com/openset/leetcode/tree/master/problems/max-consecutive-ones-iii) | [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Medium |
| 992 | [K 个不同整数的子数组](https://github.com/openset/leetcode/tree/master/problems/subarrays-with-k-different-integers) | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Hard |
| 986 | [区间列表的交集](https://github.com/openset/leetcode/tree/master/problems/interval-list-intersections) | [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] | Medium |
Expand Down