Skip to content

Commit 928a60a

Browse files
fix build for 914
1 parent 6e473a5 commit 928a60a

File tree

1 file changed

+16
-11
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+16
-11
lines changed

src/main/java/com/fishercoder/solutions/_914.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import java.util.Map;
55

66
/**
7+
* 914. X of a Kind in a Deck of Cards
8+
*
79
* In a deck of cards, each card has an integer written on it.
810
* Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:
9-
* Each group has exactly X cards.
10-
* All the cards in each group have the same integer.
11+
* Each group has exactly X cards.
12+
* All the cards in each group have the same integer.
1113
*
1214
* Example 1:
1315
* Input: [1,2,3,4,4,3,2,1]
@@ -38,22 +40,24 @@ public class _914 {
3840
public static class Solution1 {
3941
public boolean hasGroupsSizeX(int[] deck) {
4042
//Size too small for partitions
41-
if (deck.length < 2)
43+
if (deck.length < 2) {
4244
return false;
45+
}
4346

4447
//Track repetitions of values in deck array
4548
Map<Integer, Integer> mapReps = new HashMap<>();
4649
for (int card : deck) {
47-
if (!mapReps.containsKey(card))
48-
mapReps.put(card,1);
49-
else
50-
mapReps.put(card,mapReps.get(card)+1);
50+
if (!mapReps.containsKey(card)) {
51+
mapReps.put(card, 1);
52+
} else {
53+
mapReps.put(card, mapReps.get(card) + 1);
54+
}
5155
}
5256

5357
//Create array of map values
5458
int num = 0;
5559
int[] arrReps = new int[mapReps.size()];
56-
for (Map.Entry<Integer,Integer> e : mapReps.entrySet()){
60+
for (Map.Entry<Integer, Integer> e : mapReps.entrySet()) {
5761
arrReps[num++] = e.getValue();
5862
}
5963

@@ -64,14 +68,15 @@ public boolean hasGroupsSizeX(int[] deck) {
6468
return num > 1;
6569
}
6670

67-
private int gcd(int a, int b){
71+
private int gcd(int a, int b) {
6872
return b == 0 ? a : gcd(b, a % b);
6973
}
7074

71-
private int arrGCD(int[] arr, int n){
75+
private int arrGCD(int[] arr, int n) {
7276
int result = arr[0];
73-
for (int i = 1; i < n; i++)
77+
for (int i = 1; i < n; i++) {
7478
result = gcd(arr[i], result);
79+
}
7580

7681
return result;
7782
}

0 commit comments

Comments
 (0)