当前位置:网站首页>[Jianzhi offer] 61 Shunzi in playing cards
[Jianzhi offer] 61 Shunzi in playing cards
2022-07-05 16:58:00 【LuZhouShiLi】
The finger of the sword Offer 61. Shunzi in playing cards
subject
Draw at random from several sets of playing cards 5 card , Judge whether it's a down son , Is this 5 Are cards continuous .2~10 For the number itself ,A by 1,J by 11,Q by 12,K by 13, And big 、 Wang Wei 0 , It can be seen as any number .A Can't be regarded as 14.
Ideas
Three things
- First, sort the array
- In the statistics array 0 The number of
- Finally, count the total number of vacancies between adjacent numbers in the sorted array
- Judge 0 Whether the number of is greater than or equal to the total number of vacancies
Code
class Solution {
public:
bool isStraight(vector<int>& nums) {
sort(nums.begin(),nums.end());// Sort
int king = 0;
int gap = 0;
for(int i = 0; i < nums.size(); ++i)
{
if(nums[i] == 0)
{
++king;// Statistics 0 The number of
}
if(i > 0 && nums[i] != 0 && nums[i] == nums[i - 1])
{
return false;// Encounter the same number
}
if(i > 0 && nums[i - 1] != 0 && nums[i] > nums[i - 1] + 1)
{
gap += nums[i] - nums[i - 1] - 1;// Calculate vacancy Remember to subtract one
}
}
return king >= gap;// Judge 0 Whether the number of is greater than the number of vacancies
}
};
边栏推荐
- The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
- ECU introduction
- Jarvis OJ Webshell分析
- Practical example of propeller easydl: automatic scratch recognition of industrial parts
- Raspberry pie 4B installation pytorch1.11
- 【729. 我的日程安排錶 I】
- Data verification before and after JSON to map -- custom UDF
- Summary of PHP pseudo protocol of cisp-pte
- 拷贝方式之DMA
- 飞桨EasyDL实操范例:工业零件划痕自动识别
猜你喜欢

Deep dive kotlin synergy (XXI): flow life cycle function

數據訪問 - EntityFramework集成

Learnopongl notes (II) - Lighting

文件操作--I/O
![[729. My Schedule i]](/img/e3/32914227d00cf7595ee850e60f2b72.png)
[729. My Schedule i]

【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识

清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会

The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale

How was the middle table destroyed?

Data access - entityframework integration
随机推荐
Win11如何给应用换图标?Win11给应用换图标的方法
Deep learning plus
【机器人坐标系第一讲】
Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
外盘期货平台如何辨别正规安全?
为季前卡牌游戏 MotoGP Ignition Champions 做好准备!
數據訪問 - EntityFramework集成
Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found
国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」
[深度学习][原创]让yolov6-0.1.0支持yolov5的txt读取数据集模式
网站页面禁止复制内容 JS代码
清晰还原31年前现场,火山引擎超清修复Beyond经典演唱会
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
Jarvis OJ Flag
Games101 notes (III)
Android privacy sandbox developer preview 3: privacy, security and personalized experience
Benji Bananas 会员通行证持有人第二季奖励活动更新一览
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL