-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicates.cs
More file actions
90 lines (66 loc) · 1.8 KB
/
Duplicates.cs
File metadata and controls
90 lines (66 loc) · 1.8 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
namespace DuplicatedInArr
{
class DupArr
{
public static bool Duplicates(int[] nums)
{
HashSet<int> numbs = new HashSet<int>();
for (int i = 0; i < nums.Length; i++)
{
if (numbs.Contains(nums[i])) return true;
numbs.Add(nums[i]);
}
return false;
}
public static int CalculateAverage(IEnumerable<int> numbers)
{
// Write your code here
List<int> nums = numbers.ToList();
List<int> checkRepeat = new List<int>();
double total = 0;
int avg = 0;
for (int i = 0; i < nums.Count; i++)
{
if (!checkRepeat.Contains(nums[i]))
checkRepeat.Add(nums[i]);
}
foreach (int n in checkRepeat)
{
total += n;
}
avg = (int)Math.Ceiling(total / checkRepeat.Count);
return avg;
}
public static String check_special(int n, int p)
{
int count = 0;
while (n % 2 == 0)
{
n /= 2;
count++;
}
for (int i = 3; i <= Math.Sqrt(n); i += 2)
{
while (n % i == 0)
{
n /= i;
}
}
if (n >= 2)
{
return "YES";
}
return "NO";
}
public static void MainC(string[] args)
{
int[] nums = new int[] { 1, 2, 2, 3 };
// Duplicates(nums);
// CalculateAverage(nums);
check_special(2, 7);
}
}
}