当前位置:网站首页>Leetcode · 83 biweekly match · 6128. best poker hand · simulation
Leetcode · 83 biweekly match · 6128. best poker hand · simulation
2022-07-26 03:11:00 【Xiao Xun wants to be strong】
link :https://leetcode.cn/problems/best-poker-hand/solution/jian-dan-mo-ni-by-xun-ge-v-q4zp/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
subject

Example

Ideas
Their thinking
simulation
Simulate according to the given requirements of the topic
Two arrays will be given , Do a simple treatment , Make the same size , Count the cards with the same color , Then the array after statistics , Sort in descending order , Then judge the card type whose maximum value meets the requirements according to the requirements of the title
Code
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);// initialization
memset(str, 0, sizeof(int) * 4);// initialization
for(int i = 0; i < ranksSize; i++)// Deal with cards
{
ans[ranks[i]]++;
str[suits[i] - 'a']++;
}
qsort(ans, 14, sizeof(int), cmp);
qsort(str, 4, sizeof(int), cmp);// Descending
if(str[0] == 5)// Judge card type
{
return "Flush";
}
if(ans[0] >= 3)
{
return "Three of a Kind";
}
if(ans[0] == 2)
{
return "Pair";
}
return "High Card";
}
author :xun-ge-v
link :https://leetcode.cn/problems/best-poker-hand/solution/jian-dan-mo-ni-by-xun-ge-v-q4zp/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .Time and space complexity

边栏推荐
猜你喜欢

Summary of Huawei virtualization fusioncompute knowledge points

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

Arthas view the source code of the loaded class (JAD)

STM——EXTI外部中断学习笔记

Software testing post: Ali has three sides. Fortunately, he has made full preparations and has been offered

Opencv报错:(parameter or structure field))Unrecognized or unsupported array type in functon ‘cvGetMat‘

ByteDance (Tiktok) software test monthly salary 23K post, technical two-sided interview questions are newly released

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

File operation (I) -- File introduction and file opening and closing methods

How to correctly calculate the CPU utilization of kubernetes container
随机推荐
Matlab simulation of vertical handover between MTD SCDMA and TD LTE dual networks
Pit trodden when copying list: shallow copy and deep copy
[sql] case expression
[translation] announce Vites 13
Nahamcon CTF 2022 babyrev reverse analysis
Multithreaded programming
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 1)
【C进阶】深入探索数据的存储(深度剖析+典例解读)
Swin Transformer【Backbone】
How to install with USB flash disk?
Skill list of image processing experts
Golang log programming system
Jsd-2204-cool shark Mall (Management Commodity module) -day02
LeetCode·每日一题·919.完全二叉树插入器·层次遍历·BFS
[detailed explanation of key and difficult points of document operation]
How can users create data tables on Web pages and store them in the database
手把手教你依赖管理
An article allows you to understand the relevance of cloud native containerization
Qt 信号在多层次对象间传递 多层嵌套类对象之间信号传递
How about GF Securities? Is it safe to open an account online?