-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
71 lines (63 loc) · 1.52 KB
/
Solution.cs
File metadata and controls
71 lines (63 loc) · 1.52 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#if DEBUG
using System.Collections;
#endif
public class MyHashSet
{
BitArray buckets;
int maxKey = (int)1e6 + 1;
public MyHashSet()
{
buckets = new BitArray(maxKey);
}
public void Add(int key)
{
buckets[key] = true;
}
public void Remove(int key)
{
buckets[key] = false;
}
public bool Contains(int key)
{
return buckets[key];
}
}
/**
* Your MyHashSet object will be instantiated and called as such:
* MyHashSet obj = new MyHashSet();
* obj.Add(key);
* obj.Remove(key);
* bool param_3 = obj.Contains(key);
*/
public class Solution
{
public List<dynamic> Execute(string[] actions, int[][] values)
{
List<dynamic> result = [];
MyHashSet myHashSet = null;
for (int i = 0; i < actions.Length; i++)
{
switch (actions[i])
{
case "MyHashSet":
myHashSet = new MyHashSet();
result.Add(null);
break;
case "add":
myHashSet.Add(values[i][0]);
result.Add(null);
break;
case "remove":
myHashSet.Remove(values[i][0]);
result.Add(null);
break;
case "contains":
result.Add(myHashSet.Contains(values[i][0]));
break;
default:
break;
}
}
return result;
}
}