Skip to content

Commit cf8a578

Browse files
Merge pull request #1817 from CodingTestStudy2/염혜정
[염혜정] Day14
2 parents 46bb5c3 + f820a64 commit cf8a578

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// O(nlogn)
2+
3+
import java.util.Arrays;
4+
5+
class Solution {
6+
public boolean hasGroupsSizeX(int[] deck) {
7+
Arrays.sort(deck);
8+
9+
int g = 0;
10+
int count = 1;
11+
for (int i = 1; i <= deck.length; i++) {
12+
if (i < deck.length && deck[i] == deck[i - 1]) {
13+
count++;
14+
} else {
15+
g = gcd(g, count);
16+
count = 1;
17+
}
18+
}
19+
return g >= 2;
20+
}
21+
22+
private int gcd(int a, int b) {
23+
return b == 0 ? a : gcd(b, a % b);
24+
}
25+
}

0 commit comments

Comments
 (0)