Skip to content

Commit fe20ed6

Browse files
committed
Add 914-XofAkindInAdeckOfCards.cpp
1 parent d027ae5 commit fe20ed6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int gcd(int a, int b){return (b == 0) ? a : gcd(b, a % b);}
2+
3+
class Solution {
4+
public:
5+
bool hasGroupsSizeX(vector<int>& deck) {
6+
std::map<int, int> m;
7+
for(int p = 0; p < deck.size(); p++){++m[deck[p]];}
8+
9+
int cnt(0);
10+
for(std::map<int, int>::iterator it = m.begin(); it != m.end(); it++){
11+
int cur = it->second;
12+
cnt = gcd(cur, cnt);
13+
if(cnt <= 1){return false;}
14+
}
15+
16+
return true;
17+
}
18+
};

0 commit comments

Comments
 (0)