-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0217-Contains-Duplicate.cs
More file actions
35 lines (30 loc) · 963 Bytes
/
0217-Contains-Duplicate.cs
File metadata and controls
35 lines (30 loc) · 963 Bytes
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
using System;
using System.Collections.Generic;
using System.Text;
namespace Solution._0217.Contains_Duplicate
{
public class _0217_Contains_Duplicate
{
public bool ContainsDuplicate(int[] nums)
{
HashSet<int> hash = new HashSet<int>();
foreach (var num in nums)
{
if (!hash.Add(num))
return true;
}
return false;
// Solution 1
/* Runtime: 2388 ms, faster than 5.19% of C# online submissions for Contains Duplicate.
* Memory Usage: 29.5 MB, less than 79.02% of C# online submissions for Contains Duplicate.
*/
//for (int i = 0; i < nums.Length; i++)
//{
// for (int j = i + 1; j < nums.Length; j++)
// if (nums[i] == nums[j])
// return true;
//}
//return false;
}
}
}