Skip to content

Commit 2e72b3d

Browse files
add 1114
1 parent 84e00e2 commit 2e72b3d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ _If you like this project, please leave me a star._ ★
189189
|1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1170.java) | |Easy||
190190
|1119|[Remove Vowels from a String](https://leetcode.com/problems/remove-vowels-from-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1119.java) | [:tv:](https://www.youtube.com/watch?v=6KCBrIWEauw)|Easy||
191191
|1118|[Number of Days in a Month](https://leetcode.com/problems/number-of-days-in-a-month/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1118.java) | |Easy||
192+
|1114|[Print in Order](https://leetcode.com/problems/print-in-order/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1114.java) | |Easy||
192193
|1108|[Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1108.java) | [:tv:](https://www.youtube.com/watch?v=FP0Na-pL0qk)|Easy||
193194
|1104|[Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1104.java) | |Medium|Math, Tree|
194195
|1103|[Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1103.java) | |Easy|Math|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1114 {
4+
public static class Solution1 {
5+
static class Foo {
6+
7+
private static volatile boolean onePrinted;
8+
private static volatile boolean twoPrinted;
9+
10+
public Foo() {
11+
onePrinted = false;
12+
twoPrinted = false;
13+
}
14+
15+
public synchronized void first(Runnable printFirst) throws InterruptedException {
16+
17+
// printFirst.run() outputs "first". Do not change or remove this line.
18+
printFirst.run();
19+
onePrinted = true;
20+
notifyAll();
21+
}
22+
23+
public synchronized void second(Runnable printSecond) throws InterruptedException {
24+
while (!onePrinted) {
25+
wait();
26+
}
27+
28+
// printSecond.run() outputs "second". Do not change or remove this line.
29+
printSecond.run();
30+
twoPrinted = true;
31+
notifyAll();
32+
}
33+
34+
public synchronized void third(Runnable printThird) throws InterruptedException {
35+
while (!twoPrinted) {
36+
wait();
37+
}
38+
39+
// printThird.run() outputs "third". Do not change or remove this line.
40+
printThird.run();
41+
}
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)