【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; 完
随机推荐
- javascript之大文件分段上传、断点续传
这里只写后端的代码,基本的思想就是,前端将文件分片,然后每次访问上传接口的时候,向后端传入参数:当前为第几块文件,和分片总数 下面直接贴代码吧,一些难懂的我大部分都加上注释了: 上传文件实体类: 看得 ...
- [TJOI2019]甲苯先生和大中锋的字符串
有个叫asuldb的神仙来嘲讽我 说这题SAM水题,而且SA过不了 然后我就用SA过了 显然是一个Height数组上长为k的滑块,判一下两边,差分一下就可以了 #include"cstdio ...
- C#中的Byte,String,Int,Hex之间的转换函数。
/// <summary> Convert a string of hex digits (ex: E4 CA B2) to a byte array. </summary> ...
- LOJ575. 「LibreOJ NOI Round #2」不等关系 [容斥,分治FFT]
LOJ 思路 发现既有大于又有小于比较难办,使用容斥,把大于改成任意减去小于的. 于是最后的串就长成这样:<<?<?<??<<<?<.我们把一段连续的& ...
- js将数组分割成等长数组
方法一: function group(array, subGroupLength) { let index = 0; let newArray = []; while(index < arra ...
- yyy
def delete(ps): import os filename = ps[-] delelemetns = ps[] with open(filename, encoding='utf-8') ...
- SpringBoot整合ElasticSearch:基于Jest技术
1.给pom.xml添加依赖 <!--SpringBoot默认使用SpringData ElasticSearch模块进行操作 <dependency> <groupId> ...
- SignalR的几种方式_转自:https://www.cnblogs.com/zuowj/p/5674615.html
SignalR有三种传输模式: LongLooping(长轮询). WebSocket(HTML5的WEB套接字). Forever Frame(隐藏框架的长请求连接), 可以在WEB客户端显式指定一 ...
- Mybatis笔记(二)
目录 MyBatis 逆向工程 MyBatis Generator 使用 分页插件 1.下载分页插件 2.配置分页插件 3.使用分页插件 SSM整合(spring与springMVC) 1.创建web ...
- HTML5中的article和section的区别
HTML5中的article和section的区别 一.总结 一句话总结: article和section都相当于语义化后的div,article强调独立性,section强调分段或者分块 1.art ...