当前位置:网站首页>LeetCode Algorithm 914. 卡牌分组
LeetCode Algorithm 914. 卡牌分组
2022-08-10 09:55:00 【Alex_996】
题目链接:914. 卡牌分组
Ideas
算法:最大公约数
数据结构:无
思路:统计所有牌的个数,找到最大公约数,如果最大公约数大于等于2,返回true,否则返回false。
Code
C++
class Solution {
public:
bool hasGroupsSizeX(vector<int>& deck) {
unordered_map<int, int> cnt;
for (int num : deck) {
cnt[num]++;
}
int gcd_num = cnt.begin()->second;
for (auto &iter : cnt) {
gcd_num = gcd(iter.second, gcd_num);
}
return gcd_num > 1;
}
};
边栏推荐
- Behind iFLYTEK's translation machine stealing the spotlight, cross-language communication has entered a new era
- PostgreSQL 2022 发展现状:13 个非 psql 工具
- web项目访问引用jar内部的静态资源
- 《广州市公路工程安全生产监督管理办法》印发,从六大方面进行修订
- 【数据库架构】OLTP 和 OLAP:实际比较
- vs2012创建WCF应用程序
- 07 【动态组件 组件注册】
- Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference
- 腾讯发布四足机器人 Max 二代版本,梅花桩上完成跳跃、空翻
- JS高级 之 使用 Iterator - Generator
猜你喜欢
随机推荐
「应用架构」TOGAF建模:企业可管理性图
故障分析 | Sql_slave_skip_counter 使用不规范对复制的影响
多租户技术
Excel绘制统计图
「业务架构」TOGAF建模:业务功能分解图
【API Management】What is API Management and why is it important?
Behind iFLYTEK's translation machine stealing the spotlight, cross-language communication has entered a new era
06 【生命周期 模板引用】
并发的基本概念,操作,容器
第三章 搜索与图论(三)
JS高级 之 Promise 详解
重学冒泡排序
ESP8266-Arduino编程实例-MQ-9 一氧化碳可燃气体传感器驱动
mysql千万级别数据库优化
反射效率为什么低?
武功修炼:内功
"Guangzhou highway engineering measures for the supervision and administration of production safety, and revised from six aspects
07 【动态组件 组件注册】
用高质量图像标注数据加速AI商业化落地
JWT:拥有我,即拥有权力









