-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy path1114-PrintInOrder.cs
50 lines (39 loc) · 1.23 KB
/
1114-PrintInOrder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//-----------------------------------------------------------------------------
// Runtime: 112ms
// Memory Usage: 25.1 MB
// Link: https://leetcode.com/submissions/detail/333626473/
//-----------------------------------------------------------------------------
using System;
using System.Threading;
namespace LeetCode
{
public class Foo
{
private EventWaitHandle waitHandle1;
private EventWaitHandle waitHandle2;
public Foo()
{
waitHandle1 = new AutoResetEvent(false);
waitHandle2 = new AutoResetEvent(false);
}
public void First(Action printFirst)
{
// printFirst() outputs "first". Do not change or remove this line.
printFirst();
waitHandle1.Set();
}
public void Second(Action printSecond)
{
waitHandle1.WaitOne();
// printSecond() outputs "second". Do not change or remove this line.
printSecond();
waitHandle2.Set();
}
public void Third(Action printThird)
{
waitHandle2.WaitOne();
// printThird() outputs "third". Do not change or remove this line.
printThird();
}
}
}