当前位置:网站首页>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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。时间空间复杂度

边栏推荐
- 【C进阶】深入探索数据的存储(深度剖析+典例解读)
- Software testing post: Ali has three sides. Fortunately, he has made full preparations and has been offered
- 这种动态规划你见过吗——状态机动态规划之股票问题(上)
- Autojs cloud control source code + display
- How to install with USB flash disk?
- How to design test cases according to the requirements of login testing?
- STM32——串口学习笔记(一个字节、16位数据、字符串、数组)
- The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track
- STM32——DMA笔记
- 【C语言】深入理解 整型提升 和 算术转换
猜你喜欢

Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?

Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation

如何用U盘进行装机?

snownlp库各功能及用法

Win11更改磁盘驱动器号的方法

What if the test / development programmer gets old? Lingering cruel facts

VR panoramic shooting and production of business center helps businesses effectively attract people

对于稳定性测试必需关注的26点

Games101 review: shading, rendering pipelines

循环与分支(一)
随机推荐
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (reconstruction)
The sixth day of the third question of daily Luogu
图像识别(六)| 激活函数
ShardingSphere数据分片
Quick check of OGC WebGIS common service standards (wms/wmts/tms/wfs)
Image recognition (VI) | activation function
Qt 信号在多层次对象间传递 多层嵌套类对象之间信号传递
How about GF Securities? Is it safe to open an account online?
中国信通院陈屹力:降本增效是企业云原生应用的最大价值
The source of everything, the choice of code branching strategy
ES6 set and map
VOFA+ 串口调试助手
[NOIP2001 普及组] 最大公约数和最小公倍数问题
【无标题】
Multithreaded programming
Code dynamically controls textview to move right (not XML)
[steering wheel] tool improvement: common shortcut key set of sublime text 4
Golang log programming system
Cycle and branch (I)
An article allows you to understand the relevance of cloud native containerization