Skip to content

Commit 91c11c0

Browse files
author
openset
committed
Add: new
1 parent 568e009 commit 91c11c0

File tree

8 files changed

+274
-1
lines changed

8 files changed

+274
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <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 |
58+
| <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 |
59+
| <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 |
60+
| <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 |
5761
| <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 |
5862
| <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 |
5963
| <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 |

problems/brace-expansion-ii/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array "Find in Mountain Array")
9+
                
10+
Next >
11+
12+
## 1096. Brace Expansion II (Hard)
13+
14+
<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>
15+
16+
<p>Grammar can best be understood through simple examples:</p>
17+
18+
<ul>
19+
<li>Single letters represent a singleton set containing that word.
20+
<ul>
21+
<li><code>R(&quot;a&quot;) = {&quot;a&quot;}</code></li>
22+
<li><code>R(&quot;w&quot;) = {&quot;w&quot;}</code></li>
23+
</ul>
24+
</li>
25+
<li>When we take a comma delimited list of 2 or more expressions, we take the union of possibilities.
26+
<ul>
27+
<li><code>R(&quot;{a,b,c}&quot;) = {&quot;a&quot;,&quot;b&quot;,&quot;c&quot;}</code></li>
28+
<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>
29+
</ul>
30+
</li>
31+
<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.
32+
<ul>
33+
<li><code>R(&quot;{a,b}{c,d}&quot;) = {&quot;ac&quot;,&quot;ad&quot;,&quot;bc&quot;,&quot;bd&quot;}</code></li>
34+
<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>
35+
</ul>
36+
</li>
37+
</ul>
38+
39+
<p>Formally, the 3 rules for our grammar:</p>
40+
41+
<ul>
42+
<li>For every lowercase letter <code>x</code>, we have <code>R(x) = {x}</code></li>
43+
<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>
44+
<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>
45+
</ul>
46+
47+
<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>
48+
49+
<p>&nbsp;</p>
50+
51+
<div>
52+
<p><strong>Example 1:</strong></p>
53+
54+
<pre>
55+
<strong>Input: </strong><span id="example-input-1-1">&quot;{a,b}{c{d,e}}&quot;</span>
56+
<strong>Output: </strong><span id="example-output-1">[&quot;acd&quot;,&quot;ace&quot;,&quot;bcd&quot;,&quot;bce&quot;]</span>
57+
</pre>
58+
59+
<div>
60+
<p><strong>Example 2:</strong></p>
61+
62+
<pre>
63+
<strong>Input: </strong><span>&quot;{{a,z},a{b,c},{ab,z}}&quot;</span>
64+
<strong>Output: </strong><span>[&quot;a&quot;,&quot;ab&quot;,&quot;ac&quot;,&quot;z&quot;]</span>
65+
<strong>Explanation: </strong>Each distinct word is written only once in the final answer.
66+
</pre>
67+
68+
<p>&nbsp;</p>
69+
70+
<p><strong>Constraints:</strong></p>
71+
72+
<ol>
73+
<li><code>1 &lt;= expression.length &lt;= 50</code></li>
74+
<li><code>expression[i]</code> consists of <code>&#39;{&#39;</code>, <code>&#39;}&#39;</code>, <code>&#39;,&#39;</code>or lowercase English letters.</li>
75+
<li>The given&nbsp;<code>expression</code>&nbsp;represents a set of words based on the grammar given in the description.</li>
76+
</ol>
77+
</div>
78+
</div>

problems/car-pooling/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/statistics-from-a-large-sample "Statistics from a Large Sample")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/find-in-mountain-array "Find in Mountain Array")
11+
12+
## 1094. Car Pooling (Medium)
13+
14+
<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>
15+
16+
<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>
17+
18+
<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>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong>Example 1:</strong></p>
23+
24+
<pre>
25+
<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>
26+
<strong>Output: </strong><span id="example-output-1">false</span>
27+
</pre>
28+
29+
<div>
30+
<p><strong>Example 2:</strong></p>
31+
32+
<pre>
33+
<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>
34+
<strong>Output: </strong><span id="example-output-2">true</span>
35+
</pre>
36+
37+
<div>
38+
<p><strong>Example 3:</strong></p>
39+
40+
<pre>
41+
<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>
42+
<strong>Output: </strong><span id="example-output-3">true</span>
43+
</pre>
44+
45+
<div>
46+
<p><strong>Example 4:</strong></p>
47+
48+
<pre>
49+
<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>
50+
<strong>Output: </strong><span id="example-output-4">true</span>
51+
</pre>
52+
</div>
53+
</div>
54+
</div>
55+
56+
<div>
57+
<div>
58+
<div>
59+
<div>&nbsp;</div>
60+
</div>
61+
</div>
62+
</div>
63+
64+
<p>&nbsp;</p>
65+
<p><strong>Constraints:</strong></p>
66+
67+
<ol>
68+
<li><code>trips.length &lt;= 1000</code></li>
69+
<li><code>trips[i].length == 3</code></li>
70+
<li><code>1 &lt;= trips[i][0] &lt;= 100</code></li>
71+
<li><code>0 &lt;= trips[i][1] &lt; trips[i][2] &lt;= 1000</code></li>
72+
<li><code>1 &lt;=&nbsp;capacity &lt;= 100000</code></li>
73+
</ol>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/brace-expansion-ii "Brace Expansion II")
11+
12+
## 1095. Find in Mountain Array (Hard)
13+
14+
<p><em>(This problem is an&nbsp;<strong>interactive problem</strong>.)</em></p>
15+
16+
<p>You may recall that an array&nbsp;<code>A</code> is a <em>mountain array</em> if and only if:</p>
17+
18+
<ul>
19+
<li><code>A.length &gt;= 3</code></li>
20+
<li>There exists some&nbsp;<code>i</code>&nbsp;with&nbsp;<code>0 &lt; i&nbsp;&lt; A.length - 1</code>&nbsp;such that:
21+
<ul>
22+
<li><code>A[0] &lt; A[1] &lt; ... A[i-1] &lt; A[i]</code></li>
23+
<li><code>A[i] &gt; A[i+1] &gt; ... &gt; A[A.length - 1]</code></li>
24+
</ul>
25+
</li>
26+
</ul>
27+
28+
<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>
29+
30+
<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>
31+
32+
<ul>
33+
<li><code>MountainArray.get(k)</code> returns the element of the array at index <code>k</code>&nbsp;(0-indexed).</li>
34+
<li><code>MountainArray.length()</code>&nbsp;returns the length of the array.</li>
35+
</ul>
36+
37+
<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>
38+
39+
<ol>
40+
</ol>
41+
42+
<p>&nbsp;</p>
43+
<p><strong>Example 1:</strong></p>
44+
45+
<pre>
46+
<strong>Input:</strong> array = [1,2,3,4,5,3,1], target = 3
47+
<strong>Output:</strong> 2
48+
<strong>Explanation:</strong> 3 exists in the array, at index=2 and index=5. Return the minimum index, which is 2.</pre>
49+
50+
<p><strong>Example 2:</strong></p>
51+
52+
<pre>
53+
<strong>Input:</strong> array = [0,1,2,4,2,1], target = 3
54+
<strong>Output:</strong> -1
55+
<strong>Explanation:</strong> 3 does not exist in <code>the array,</code> so we return -1.
56+
</pre>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ol>
62+
<li><code>3 &lt;= mountain_arr.length() &lt;= 10000</code></li>
63+
<li><code>0 &lt;= target &lt;= 10^9</code></li>
64+
<li><code>0 &lt;= mountain_arr.get(index) &lt;=&nbsp;10^9</code></li>
65+
</ol>

problems/shortest-common-supersequence/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-path-in-binary-matrix "Shortest Path in Binary Matrix")
99

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

1212
## 1092. Shortest Common Supersequence (Hard)
1313

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!--|This file generated by command(leetcode description); DO NOT EDIT. |-->
2+
<!--+----------------------------------------------------------------------+-->
3+
<!--|@author Openset <[email protected]> |-->
4+
<!--|@link https://github.com/openset |-->
5+
<!--|@home https://github.com/openset/leetcode |-->
6+
<!--+----------------------------------------------------------------------+-->
7+
8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/shortest-common-supersequence "Shortest Common Supersequence")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/car-pooling "Car Pooling")
11+
12+
## 1093. Statistics from a Large Sample (Medium)
13+
14+
<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>
15+
16+
<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>
17+
18+
<p><em>(Recall that the median of a sample is:</em></p>
19+
20+
<ul>
21+
<li><em>The middle element, if the elements of the sample were sorted and the number of elements is odd;</em></li>
22+
<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>
23+
</ul>
24+
25+
<p>&nbsp;</p>
26+
<p><strong>Example 1:</strong></p>
27+
<pre><strong>Input:</strong> count = [0,1,3,4,0,0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
31+
<strong>Output:</strong> [1.00000,4.00000,2.18182,2.00000,1.00000]
32+
</pre>
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ol>
37+
<li><code>count.length == 256</code></li>
38+
<li><code>1 &lt;= sum(count) &lt;= 10^9</code></li>
39+
<li>The mode of the sample that count represents is unique.</li>
40+
<li>Answers within <code>10^-5</code> of the true value will be accepted as correct.</li>
41+
</ol>
42+
43+
### Related Topics
44+
[[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)]
45+
[[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)]
46+
47+
### Hints
48+
<details>
49+
<summary>Hint 1</summary>
50+
The hard part is the median. Write a helper function which finds the k-th element from the sample.
51+
</details>

tag/math/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 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 |
1213
| 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 |
1314
| 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 |
1415
| 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 |

tag/two-pointers/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
| # | 题名 | 标签 | 难度 |
1111
| :-: | - | - | :-: |
12+
| 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 |
1213
| 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 |
1314
| 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 |
1415
| 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 |

0 commit comments

Comments
 (0)