problem

914. X of a Kind in a Deck of Cards

题意:每个数字对应的数目可以均分为多组含有K个相同数目该数字的数组。

思路:使用 map 结构记录数组中每个元素出现的次数,该题转化为求次数的最大公约数,若所有次数的最大公约数大于或者等于 2,返回 true,否则返回 false。

solution:

class Solution {
public:
bool hasGroupsSizeX(vector<int>& deck) {
//Greatest Common Divisor(GCD)
int tmp = ;
unordered_map<int, int> cnt;
for(auto a:deck) cnt[a]++;
for(auto a:cnt) tmp = __gcd(a.second, tmp);
return tmp>;
}
/*
int gcd(int a, int b)
{ }*/
};

参考

1. Leetcode_easy_914. X of a Kind in a Deck of Cards;

2. discuss;

【Leetcode_easy】914. X of a Kind in a Deck of Cards的更多相关文章

  1. 【LeetCode】914. X of a Kind in a Deck of Cards 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 最大公约数 日期 题目地址: https:// ...

  2. 【CodeForces】914 F. Substrings in a String bitset

    [题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...

  3. 【CodeForces】914 E. Palindromes in a Tree 点分治

    [题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2 ...

  4. 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合

    [题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...

  5. [LeetCode] 914. X of a Kind in a Deck of Cards 一副牌中的X

    In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...

  6. 【Leetcode_easy】1021. Remove Outermost Parentheses

    problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完

  7. 【Leetcode_easy】1022. Sum of Root To Leaf Binary Numbers

    problem 1022. Sum of Root To Leaf Binary Numbers 参考 1. Leetcode_easy_1022. Sum of Root To Leaf Binar ...

  8. 【Leetcode_easy】1025. Divisor Game

    problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完

  9. 【Leetcode_easy】1029. Two City Scheduling

    problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完

随机推荐

  1. HTML中的标签列表

    1 :基础标签 <!DOCTYPE> :定义文档类型 <title>:定义文档标题 <h1>to<h2>定义HTML标题,其中h1到h6表示字体大小依次 ...

  2. nginx反向代理 报错:Error during WebSocket handshake: Unexpected response code: 403

    遇到nginx报错:websocket wss failed: Error during WebSocket handshake: Unexpected response code: 403 serv ...

  3. 常用的两种web单点登录SSO的实现原理

    单点登录SSO(Single Sign On)说得简单点就是在一个多系统共存的环境下,用户在一处登录后,就不用在其他系统中登录,也就是用户的一次登录能得到其他所有系统的信任.单点登录在大型网站里使用得 ...

  4. 洛谷 P3375 【模板】KMP字符串匹配 题解

    KMP模板,就不解释了 #include<iostream> #include<cstdio> #include<cstring> #include<algo ...

  5. YAML_18 ansible 判断和循环

    标准循环 模式一 - name: add several users user: name={{ item }} state=present groups=wheel with_items: - te ...

  6. RegularExpression正则表达式

    1.必須為大寫字母,小寫字母,數字和符號的至少其中3種組合 The new password should contain any three of different syntax which is ...

  7. 2017.10.3 国庆清北 D3T1 括号序列

    题目描述 LYK有一个括号序列,但这个序列不一定合法. 一个合法的括号序列如下: ()是合法的括号序列. 若A是合法的括号序列,则(A)是合法的括号序列. 若A和B分别是合法的括号序列,则AB是合法的 ...

  8. mysql bigint与bigint unsigned

    -------------------------------以下是个人根据网上翻阅加个人理解总结结果------------------------------- mysql 表中数据类型和存储过程 ...

  9. Linux 系统安装下安装 mysql5.7(glibc版)

    转自:https://www.cnblogs.com/mujingyu/p/7689116.html 前言:经过一天半的折腾,终于把 mysql 5.7.17 版本安装上了 centos 7 系统上, ...

  10. 怎么将输出的字符串换行输出,replace

    var getAllData="我是第一行,我是第二行,我是第三行" var toBreak=getAllData.replace(/,/g, "\n") // ...