1
// X of a Kind in a Deck of Cards
2
// Leetcode problem : https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/
3

4
class Solution {
5
public boolean hasGroupsSizeX(int[] deck) {
6
int[] count = new int[10000];
7
for (int i : deck) count[i]++;
8
int gcd = 0;
9
for (int i : count) if (i != 0) gcd = gcd == 0 ? i : gcd(gcd, i);
10
return gcd >= 2;
11
}
12

13
private int gcd(int a, int b) {
14
return b == 0 ? a : gcd(b, a % b);
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0