当前位置:网站首页>LeetCode·83双周赛·6128.最好的扑克手牌·模拟
LeetCode·83双周赛·6128.最好的扑克手牌·模拟
2022-07-26 03:05:00 【小迅想变强】
链接:https://leetcode.cn/problems/best-poker-hand/solution/jian-dan-mo-ni-by-xun-ge-v-q4zp/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
题目

示例

思路
解题思路
模拟
按照题目给定要求进行模拟即可
将给定两个数组,进行简单的处理一下,将大小相同,花色相同的牌进行统计,然后再对统计之后的数组,进行降序排序,再按照题目要求判断最大值满足那种要求的牌型
代码
int cmp(const void * a, const void *b)
{
return *(int *)b - *(int *)a;
}
char * bestHand(int* ranks, int ranksSize, char* suits, int suitsSize){
int ans[14];
int str[4];
memset(ans, 0, sizeof(int) * 14);//初始化
memset(str, 0, sizeof(int) * 4);//初始化
for(int i = 0; i < ranksSize; i++)//对牌进行处理
{
ans[ranks[i]]++;
str[suits[i] - 'a']++;
}
qsort(ans, 14, sizeof(int), cmp);
qsort(str, 4, sizeof(int), cmp);//降序
if(str[0] == 5)//判断牌型
{
return "Flush";
}
if(ans[0] >= 3)
{
return "Three of a Kind";
}
if(ans[0] == 2)
{
return "Pair";
}
return "High Card";
}
作者:xun-ge-v
链接:https://leetcode.cn/problems/best-poker-hand/solution/jian-dan-mo-ni-by-xun-ge-v-q4zp/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。时间空间复杂度

边栏推荐
- 信息系统项目管理师必背核心考点(五十)合同内容约定不明确规定
- Case: using kept+haproxy to build a Web Cluster
- Chapter 3 business function development (delete clues)
- Execution process behind shell commands
- JVM memory model parsing
- Teach you to rely on management hand in hand
- 26 points that must be paid attention to for stability test
- How can users create data tables on Web pages and store them in the database
- 案例:使用keepalived+Haproxy搭建Web群集
- .net serialize enumeration as string
猜你喜欢

Win11大小写提示图标怎么关闭?Win11大小写提示图标的关闭方法

案例:使用keepalived+Haproxy搭建Web群集

Games101 review: shading, rendering pipelines

Quick check of OGC WebGIS common service standards (wms/wmts/tms/wfs)

【C进阶】深入探索数据的存储(深度剖析+典例解读)

OxyCon 2022 网络抓取前沿大会即将开启!

Arthas' dynamic load class (retransform)

Cycle and branch (I)

移位距离和假设的应用

STM32 - DMA notes
随机推荐
The source of everything, the choice of code branching strategy
VR panoramic shooting and production of business center helps businesses effectively attract people
Longest Substring Without Repeating Characters
如何根据登录测试的需求设计测试用例?
Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
Jenkins' study notes are detailed
FPGA_ Initial use process of vivado software_ Ultra detailed
如何正确计算 Kubernetes 容器 CPU 使用率
assert _ Aligns
Swin Transformer【Backbone】
OxyCon 2022 网络抓取前沿大会即将开启!
snownlp库各功能及用法
STM - exti external interrupt learning notes
一篇文章让你理解 云原生 容器化相关
Multithreaded programming
STM32 - DMA notes
一切的源头,代码分支策略的选择
文件操作(一)——文件简介与文件的打开方式和关闭
Design of golang lottery system
Type the URL to the web page display. What happened during this period?