forked from BigEggStudy/LeetCode-CS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1279-TrafficLightControlledIntersection.cs
More file actions
36 lines (31 loc) · 1.01 KB
/
1279-TrafficLightControlledIntersection.cs
File metadata and controls
36 lines (31 loc) · 1.01 KB
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
//-----------------------------------------------------------------------------
// Runtime: 248ms
// Memory Usage: 31.8 MB
// Link: https://leetcode.com/submissions/detail/327830218/
//-----------------------------------------------------------------------------
using System;
namespace LeetCode
{
public class TrafficLight
{
private int currentRoadId = 1;
public TrafficLight()
{
}
public void CarArrived(
int carId, // ID of the car
int roadId, // ID of the road the car travels on. Can be 1 (road A) or 2 (road B)
int direction, // Direction of the car
Action turnGreen, // Use turnGreen() to turn light to green on current road
Action crossCar // Use crossCar() to make car cross the intersection
)
{
if (roadId != currentRoadId)
{
turnGreen();
currentRoadId = roadId;
}
crossCar();
}
}
}