Skip to content

Commit e9695f9

Browse files
author
openset
committed
Add: new
1 parent 6408a01 commit e9695f9

File tree

14 files changed

+227
-10
lines changed

14 files changed

+227
-10
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ LeetCode Problems' Solutions
5454

5555
| # | Title | Solution | Difficulty |
5656
| :-: | - | - | :-: |
57+
| <span id="1117">1117</span> | [Building H2O](https://leetcode.com/problems/building-h2o) | [Go](https://github.com/openset/leetcode/tree/master/problems/building-h2o) | Hard |
58+
| <span id="1116">1116</span> | [Print Zero Even Odd](https://leetcode.com/problems/print-zero-even-odd) | [Go](https://github.com/openset/leetcode/tree/master/problems/print-zero-even-odd) | Medium |
59+
| <span id="1115">1115</span> | [Print FooBar Alternately](https://leetcode.com/problems/print-foobar-alternately) | [Go](https://github.com/openset/leetcode/tree/master/problems/print-foobar-alternately) | Medium |
60+
| <span id="1114">1114</span> | [Print in Order](https://leetcode.com/problems/print-in-order) | [Go](https://github.com/openset/leetcode/tree/master/problems/print-in-order) | Easy |
5761
| <span id="1113">1113</span> | [Reported Posts](https://leetcode.com/problems/reported-posts) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/reported-posts) | Easy |
5862
| <span id="1112">1112</span> | [Highest Grade For Each Student](https://leetcode.com/problems/highest-grade-for-each-student) 🔒 | [MySQL](https://github.com/openset/leetcode/tree/master/problems/highest-grade-for-each-student) | Medium |
5963
| <span id="1111">1111</span> | [Maximum Nesting Depth of Two Valid Parentheses Strings](https://leetcode.com/problems/maximum-nesting-depth-of-two-valid-parentheses-strings "有效括号的嵌套深度") | [Go](https://github.com/openset/leetcode/tree/master/problems/maximum-nesting-depth-of-two-valid-parentheses-strings) | Medium |

Diff for: problems/building-h2o/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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/print-zero-even-odd "Print Zero Even Odd")
9+
                
10+
Next >
11+
12+
## 1117. Building H2O (Hard)
13+
14+
<p>There are two kinds of threads, <code>oxygen</code> and <code>hydrogen</code>. Your goal is to group these threads to form water molecules.&nbsp;There is a barrier where each thread has to&nbsp;wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given a <code>releaseHydrogen</code>&nbsp;and <code>releaseOxygen</code>&nbsp;method respectfully, which will allow them to pass the barrier. These threads should pass the barrier in groups of three, and they must be able to immediately bond with each other to form a water molecule.&nbsp;You must guarantee that all the threads from one molecule bond <em>before</em> any other threads from the next molecule do.</p>
15+
16+
<p>In other words:</p>
17+
18+
<ul>
19+
<li>If an oxygen thread arrives at the barrier when no hydrogen threads are present, it has to wait for two hydrogen threads.</li>
20+
<li>If a hydrogen thread arrives at the barrier when no other threads are present, it has to wait for an oxygen thread and another hydrogen thread.</li>
21+
</ul>
22+
23+
<p>Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.</p>
24+
25+
<div>
26+
<p>&nbsp;</p>
27+
</div>
28+
29+
<div>
30+
<p><strong>Example 1:</strong></p>
31+
32+
<pre>
33+
<strong>Input: </strong><span id="example-input-1-1">&quot;HOH&quot;</span>
34+
<strong>Output: </strong><span id="example-output-1">&quot;HHO&quot;
35+
<strong>Explanation:</strong> &quot;HOH&quot; and &quot;OHH&quot; are also valid answers.</span>
36+
</pre>
37+
38+
<div>
39+
<p><strong>Example 2:</strong></p>
40+
41+
<pre>
42+
<strong>Input: </strong><span id="example-input-1-1">&quot;OOHHHH&quot;</span>
43+
<strong>Output: </strong><span id="example-output-1">&quot;HHOHHO&quot;
44+
<strong>Explanation:</strong> &quot;HOHHHO&quot;, &quot;OHHHHO&quot;, &quot;HHOHOH&quot;, &quot;HOHHOH&quot;, &quot;OHHHOH&quot;, &quot;HHOOHH&quot;, &quot;HOHOHH&quot; and &quot;OHHOHH&quot; are also valid answers.</span>
45+
</pre>
46+
</div>
47+
</div>
48+
49+
<p>&nbsp;</p>
50+
<p><strong>Constraints:</strong></p>
51+
52+
<ul>
53+
<li>Total length of input string will be 3<em>n</em>, where 1 &le;&nbsp;<em>n</em>&nbsp;&le; 50.</li>
54+
<li>Total number of <code>H</code> will be 2<em>n</em>&nbsp;in the input string.</li>
55+
<li>Total number of <code>O</code> will&nbsp;be <em>n</em>&nbsp;in the input&nbsp;string.</li>
56+
</ul>

Diff for: problems/largest-rectangle-in-histogram/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
</pre>
3434

3535
### Related Topics
36-
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3736
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
37+
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3838

3939
### Similar Questions
4040
1. [Maximal Rectangle](https://github.com/openset/leetcode/tree/master/problems/maximal-rectangle) (Hard)

Diff for: problems/maximal-rectangle/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
</pre>
2828

2929
### Related Topics
30+
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3031
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3132
[[Hash Table](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)]
3233
[[Dynamic Programming](https://github.com/openset/leetcode/tree/master/tag/dynamic-programming/README.md)]
33-
[[Stack](https://github.com/openset/leetcode/tree/master/tag/stack/README.md)]
3434

3535
### Similar Questions
3636
1. [Largest Rectangle in Histogram](https://github.com/openset/leetcode/tree/master/problems/largest-rectangle-in-histogram) (Hard)

Diff for: problems/maximum-nesting-depth-of-two-valid-parentheses-strings/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
[Next >](https://github.com/openset/leetcode/tree/master/problems/highest-grade-for-each-student "Highest Grade For Each Student")
1111

12-
## 1111. Maximum Nesting Depth of Two Valid Parentheses Strings (Hard)
12+
## 1111. Maximum Nesting Depth of Two Valid Parentheses Strings (Medium)
1313

1414
<p>A string is a <em>valid parentheses string</em>&nbsp;(denoted VPS) if and only if it consists of <code>&quot;(&quot;</code> and <code>&quot;)&quot;</code> characters only, and:</p>
1515

@@ -56,5 +56,5 @@
5656
<p><strong>Constraints:</strong></p>
5757

5858
<ul>
59-
<li><code>1 &lt;= text.size &lt;= 10000</code></li>
59+
<li><code>1 &lt;= seq.size &lt;= 10000</code></li>
6060
</ul>

Diff for: problems/print-foobar-alternately/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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/print-in-order "Print in Order")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/print-zero-even-odd "Print Zero Even Odd")
11+
12+
## 1115. Print FooBar Alternately (Medium)
13+
14+
<p>Suppose you are given the following code:</p>
15+
16+
<pre>
17+
class FooBar {
18+
public void foo() {
19+
&nbsp; &nbsp; for (int i = 0; i &lt; n; i++) {
20+
&nbsp; &nbsp; &nbsp; print(&quot;foo&quot;);
21+
&nbsp; }
22+
}
23+
24+
public void bar() {
25+
&nbsp; &nbsp; for (int i = 0; i &lt; n; i++) {
26+
&nbsp; &nbsp; &nbsp; print(&quot;bar&quot;);
27+
&nbsp; &nbsp; }
28+
}
29+
}
30+
</pre>
31+
32+
<p>The same instance of <code>FooBar</code> will be passed to two different threads. Thread A will call&nbsp;<code>foo()</code> while thread B will call&nbsp;<code>bar()</code>.&nbsp;Modify the given program to output &quot;foobar&quot; <em>n</em> times.</p>
33+
34+
<p>&nbsp;</p>
35+
36+
<p><strong>Example 1:</strong></p>
37+
38+
<pre>
39+
<b>Input:</b> n = 1
40+
<b>Output:</b> &quot;foobar&quot;
41+
<strong>Explanation:</strong> There are two threads being fired asynchronously. One of them calls foo(), while the other calls bar(). &quot;foobar&quot; is being output 1 time.
42+
</pre>
43+
44+
<p><strong>Example 2:</strong></p>
45+
46+
<pre>
47+
<b>Input:</b> n = 2
48+
<b>Output:</b> &quot;foobarfoobar&quot;
49+
<strong>Explanation:</strong> &quot;foobar&quot; is being output 2 times.
50+
</pre>
51+
52+
### Similar Questions
53+
1. [Print in Order](https://github.com/openset/leetcode/tree/master/problems/print-in-order) (Easy)
54+
1. [Print Zero Even Odd](https://github.com/openset/leetcode/tree/master/problems/print-zero-even-odd) (Medium)

Diff for: problems/print-in-order/README.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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/reported-posts "Reported Posts")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/print-foobar-alternately "Print FooBar Alternately")
11+
12+
## 1114. Print in Order (Easy)
13+
14+
<p>Suppose we have a class:</p>
15+
16+
<pre>
17+
public class Foo {
18+
&nbsp; public void one() { print(&quot;one&quot;); }
19+
&nbsp; public void two() { print(&quot;two&quot;); }
20+
&nbsp; public void three() { print(&quot;three&quot;); }
21+
}
22+
</pre>
23+
24+
<p>The same instance of <code>Foo</code> will be passed to three different threads. Thread A will call <code>one()</code>, thread B will call <code>two()</code>, and thread C will call <code>three()</code>. Design a mechanism and modify the program&nbsp;to ensure that&nbsp;<code>two()</code>&nbsp;is executed after&nbsp;<code>one()</code>, and&nbsp;<code>three()</code> is executed after&nbsp;<code>two()</code>.</p>
25+
26+
<p>&nbsp;</p>
27+
28+
<p><strong>Example 1:</strong></p>
29+
30+
<pre>
31+
<b>Input:</b> [1,2,3]
32+
<b>Output:</b> &quot;onetwothree&quot;
33+
<strong>Explanation:</strong> There are three threads being fired asynchronously. The input [1,2,3] means thread A calls one(), thread B calls two(), and thread C calls three(). &quot;onetwothree&quot; is the correct output.
34+
</pre>
35+
36+
<p><strong>Example 2:</strong></p>
37+
38+
<pre>
39+
<b>Input:</b> [1,3,2]
40+
<b>Output:</b> &quot;onetwothree&quot;
41+
<strong>Explanation:</strong> The input [1,3,2] means thread A calls one(), thread B calls three(), and thread C calls two(). &quot;onetwothree&quot; is the correct output.</pre>
42+
43+
<p>&nbsp;</p>
44+
45+
<p><strong>Note:</strong></p>
46+
47+
<p>We do not know how the threads will be scheduled in the operating system, even though the numbers in the input seems to imply the ordering. The input format you see is mainly&nbsp;to ensure our tests&#39; comprehensiveness.</p>
48+
49+
### Similar Questions
50+
1. [Print FooBar Alternately](https://github.com/openset/leetcode/tree/master/problems/print-foobar-alternately) (Medium)

Diff for: problems/print-zero-even-odd/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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/print-foobar-alternately "Print FooBar Alternately")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/building-h2o "Building H2O")
11+
12+
## 1116. Print Zero Even Odd (Medium)
13+
14+
<p>Suppose you are given the following code:</p>
15+
16+
<pre>
17+
class ZeroEvenOdd {
18+
&nbsp; public ZeroEvenOdd(int n) { ... }&nbsp; // constructor
19+
public void zero(printNumber) { ... } // only output 0&#39;s
20+
public void even(printNumber) { ... } // only output even numbers
21+
public void odd(printNumber) { ... } // only output odd numbers
22+
}
23+
</pre>
24+
25+
<p>The same instance of <code>ZeroEvenOdd</code> will be passed to three different threads:</p>
26+
27+
<ol>
28+
<li>Thread A will call&nbsp;<code>zero()</code>&nbsp;which should only output 0&#39;s.</li>
29+
<li>Thread B will call&nbsp;<code>even()</code>&nbsp;which should only ouput even numbers.</li>
30+
<li>Thread C will call <code>odd()</code>&nbsp;which should only output odd numbers.</li>
31+
</ol>
32+
33+
<p>Each of the thread is given a&nbsp;<code>printNumber</code> method to output&nbsp;an integer. Modify the given program to output the series&nbsp;<code>010203040506</code>... where the length of the series must be 2<em>n</em>.</p>
34+
35+
<p>&nbsp;</p>
36+
37+
<p><strong>Example 1:</strong></p>
38+
39+
<pre>
40+
<b>Input:</b> n = 2
41+
<b>Output:</b> &quot;0102&quot;
42+
<strong>Explanation:</strong> There are three threads being fired asynchronously. One of them calls zero(), the other calls even(), and the last one calls odd(). &quot;0102&quot; is the correct output.
43+
</pre>
44+
45+
<p><strong>Example 2:</strong></p>
46+
47+
<pre>
48+
<b>Input:</b> n = 5
49+
<b>Output:</b> &quot;0102030405&quot;
50+
</pre>
51+
52+
### Similar Questions
53+
1. [Print FooBar Alternately](https://github.com/openset/leetcode/tree/master/problems/print-foobar-alternately) (Medium)

Diff for: problems/reported-posts/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
[< Previous](https://github.com/openset/leetcode/tree/master/problems/highest-grade-for-each-student "Highest Grade For Each Student")
99

10-
Next >
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/print-in-order "Print in Order")
1111

1212
## 1113. Reported Posts (Easy)
1313

Diff for: problems/sort-colors/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
</ul>
3333

3434
### Related Topics
35+
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
3536
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3637
[[Two Pointers](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)]
37-
[[Sort](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)]
3838

3939
### Similar Questions
4040
1. [Sort List](https://github.com/openset/leetcode/tree/master/problems/sort-list) (Medium)

Diff for: problems/subsets/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
]</pre>
3333

3434
### Related Topics
35+
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)]
3536
[[Array](https://github.com/openset/leetcode/tree/master/tag/array/README.md)]
3637
[[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)]
37-
[[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)]
3838

3939
### Similar Questions
4040
1. [Subsets II](https://github.com/openset/leetcode/tree/master/problems/subsets-ii) (Medium)

Diff for: readme/301-600.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ LeetCode Problems' Solutions
100100
| <span id="344">344</span> | [Reverse String](https://leetcode.com/problems/reverse-string "反转字符串") | [Go](https://github.com/openset/leetcode/tree/master/problems/reverse-string) | Easy |
101101
| <span id="345">345</span> | [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string "反转字符串中的元音字母") | [Go](https://github.com/openset/leetcode/tree/master/problems/reverse-vowels-of-a-string) | Easy |
102102
| <span id="346">346</span> | [Moving Average from Data Stream](https://leetcode.com/problems/moving-average-from-data-stream "数据流中的移动平均值") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/moving-average-from-data-stream) | Easy |
103-
| <span id="347">347</span> | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements "前K个高频元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/top-k-frequent-elements) | Medium |
103+
| <span id="347">347</span> | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements "前 K 个高频元素") | [Go](https://github.com/openset/leetcode/tree/master/problems/top-k-frequent-elements) | Medium |
104104
| <span id="348">348</span> | [Design Tic-Tac-Toe](https://leetcode.com/problems/design-tic-tac-toe "判定井字棋胜负") 🔒 | [Go](https://github.com/openset/leetcode/tree/master/problems/design-tic-tac-toe) | Medium |
105105
| <span id="349">349</span> | [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays "两个数组的交集") | [Go](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays) | Easy |
106106
| <span id="350">350</span> | [Intersection of Two Arrays II](https://leetcode.com/problems/intersection-of-two-arrays-ii "两个数组的交集 II") | [Go](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays-ii) | Easy |

Diff for: tag/hash-table/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
| 355 | [设计推特](https://github.com/openset/leetcode/tree/master/problems/design-twitter) | [[](https://github.com/openset/leetcode/tree/master/tag/heap/README.md)] [[设计](https://github.com/openset/leetcode/tree/master/tag/design/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium |
8181
| 350 | [两个数组的交集 II](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays-ii) | [[排序](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[二分查找](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] | Easy |
8282
| 349 | [两个数组的交集](https://github.com/openset/leetcode/tree/master/problems/intersection-of-two-arrays) | [[排序](https://github.com/openset/leetcode/tree/master/tag/sort/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[双指针](https://github.com/openset/leetcode/tree/master/tag/two-pointers/README.md)] [[二分查找](https://github.com/openset/leetcode/tree/master/tag/binary-search/README.md)] | Easy |
83-
| 347 | [前K个高频元素](https://github.com/openset/leetcode/tree/master/problems/top-k-frequent-elements) | [[](https://github.com/openset/leetcode/tree/master/tag/heap/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium |
83+
| 347 | [前 K 个高频元素](https://github.com/openset/leetcode/tree/master/problems/top-k-frequent-elements) | [[](https://github.com/openset/leetcode/tree/master/tag/heap/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium |
8484
| 340 | [至多包含 K 个不同字符的最长子串](https://github.com/openset/leetcode/tree/master/problems/longest-substring-with-at-most-k-distinct-characters) 🔒 | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] [[Sliding Window](https://github.com/openset/leetcode/tree/master/tag/sliding-window/README.md)] | Hard |
8585
| 336 | [回文对](https://github.com/openset/leetcode/tree/master/problems/palindrome-pairs) | [[字典树](https://github.com/openset/leetcode/tree/master/tag/trie/README.md)] [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] [[字符串](https://github.com/openset/leetcode/tree/master/tag/string/README.md)] | Hard |
8686
| 325 | [和等于 k 的最长子数组长度](https://github.com/openset/leetcode/tree/master/problems/maximum-size-subarray-sum-equals-k) 🔒 | [[哈希表](https://github.com/openset/leetcode/tree/master/tag/hash-table/README.md)] | Medium |

0 commit comments

Comments
 (0)