【Leetcode_easy】914. X of a Kind in a Deck of Cards
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的更多相关文章
- 【LeetCode】914. X of a Kind in a Deck of Cards 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历 最大公约数 日期 题目地址: https:// ...
- 【CodeForces】914 F. Substrings in a String bitset
[题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...
- 【CodeForces】914 E. Palindromes in a Tree 点分治
[题目]E. Palindromes in a Tree [题意]给定一棵树,每个点都有一个a~t的字符,一条路径回文定义为路径上的字符存在一个排列构成回文串,求经过每个点的回文路径数.n<=2 ...
- 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...
- [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 ...
- 【Leetcode_easy】1021. Remove Outermost Parentheses
problem 1021. Remove Outermost Parentheses 参考 1. Leetcode_easy_1021. Remove Outermost Parentheses; 完
- 【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 ...
- 【Leetcode_easy】1025. Divisor Game
problem 1025. Divisor Game 参考 1. Leetcode_easy_1025. Divisor Game; 完
- 【Leetcode_easy】1029. Two City Scheduling
problem 1029. Two City Scheduling 参考 1. Leetcode_easy_1029. Two City Scheduling; 完
随机推荐
- Java【基础学习】 之调用构造方法顺序【坑】
解释:这里的super()仅仅是用来占位的,实际上,必须是严格按照分层初始化的过程:1.先初始化父类X的成员变量,即初始化成员变量Y,打印出:Y2.初始化父类X的构造方法,打印出:X3.父类初始化完成 ...
- PHP操作数据库(以MySQL为例)
一.开启扩展配置: 在php.ini的extension板块中增加一行extension=php_mysqli.dll 重启PHP,在phpinfo查看 <?php echo phpinfo() ...
- AtCoder Grand Contest 004题解
传送门 \(A\) 咕咕 int a,b,c; int main(){ scanf("%d%d%d",&a,&b,&c); if((a&1^1)|( ...
- 数据结构实验之排序二:交换排序 (SDUT 3399)
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; ...
- loadRunner目录分析<二>
loadRunner是用C语言进行编写的所以很多文件都是以.h文件结尾的 挑选一部分关键目录结构进行说明 1.analysis templates --分析模板,案例模板 2.bin --可执行程序, ...
- HTML meta pragma no-cache 页面缓存
HTML meta pragma no-cache 页面缓存不缓存页面(为了提高速度一些浏览器会缓存浏览者浏览过的页面,通过下面的定义,浏览器一般不会缓存页面,而且浏览器无法脱机浏览.) <me ...
- mybatis-sqlite日期类型对应关系
1.问题 sqlite数据库 user表,create_time字段,类型DATETIME,设置默认值datetime('now') mybatis,User实体,createTime类型为java. ...
- SpringMVC将通过ajax发送的 json数据封装成JavaBean
SpringMVC将通过ajax发送的 json数据封装成JavaBean 通过ajax发送的 json数据封装成JavaBean对发送时有如下要求: 1.发送的数据类型必须时UTF-8 2.发送的必 ...
- svn乌龟怎么用
0601 首先右键SVN-checkout 0602 其他地方可以不用修改,Version处可以修改,表示从指定版本号开始,点击OK. 0603 就会直接下载,如果改变的话,就会由绿色变成红色. 06 ...
- RabbitMQ入门学习系列(六) Exchange的Topic类型
快速阅读 介绍exchange的topic类型,和Direct类型相似,但是增加了"."和"#"的匹配.比Direct类型灵活 Topic消息类型 特点是:to ...