-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0914-XOfAKindInADeckOfCards.cs
40 lines (35 loc) · 1.04 KB
/
0914-XOfAKindInADeckOfCards.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
//-----------------------------------------------------------------------------
// Runtime: 96ms
// Memory Usage: 28.6 MB
// Link: https://leetcode.com/submissions/detail/359244266/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
using System.Linq;
namespace LeetCode
{
public class _0914_XOfAKindInADeckOfCards
{
public bool HasGroupsSizeX(int[] deck)
{
var counts = new Dictionary<int, int>();
foreach (var card in deck)
{
if (!counts.ContainsKey(card)) counts[card] = 1;
else
counts[card]++;
}
var min = counts.Values.Min();
for (var i = 2; i <= min; i++)
{
foreach (var count in counts.Values)
{
if (count % i != 0)
goto skip;
}
return true;
skip:;
}
return false;
}
}
}