当前位置:网站首页>leetcode860. Lemonade change
leetcode860. Lemonade change
2022-07-03 04:58:00 【Day by day, the dish chicken Jie!!】
One : The analects of Confucius
The little intolerance here refers to that, on the one hand, we are frustrated and can't control ourselves and lose our temper , On the other hand, we are too indecisive , For the fault of oneself or others , Do not have the heart to punish .
Two : subject

3、 ... and : Upper code
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
/** Ideas :1. As long as it is 5 Just count the change 2. When you meet 10 perhaps 20 We have to judge whether our change is enough to find , If there is enough change , Then subtract from the change Change to get back , At the same time, remember to add the money we just earned */
int change = 0;
int flag1 = 0;// Special record 5 The number of Because when we get back the change, we should pay special attention to the necessary contents 5
int flag2 = 0;// Special record 10 The number of
for(auto nums: bills) {
if(nums == 5) {
change+=nums;
flag1++;
}
if(nums == 10) {
if(change>=5 && flag1 != 0) {
change = change-5+10;
flag1--;
flag2++;
}else {
return false;
}
}
if(nums == 20) {
if(change >= 15 && flag1 != 0 && flag2 != 0) {
// The rest of the money should include 10 and 5
change = change-15+20;
flag1--;
flag2--;
}else if(change >= 15 && flag1 >= 3) {
// The rest of the money 5 The number of yuan is greater than 3 Namely 10 The number of yuan is 0
change = change-15+20;
flag1 = flag1-3;
}
else{
return false;
}
}
}
return true;
}
};

边栏推荐
- Market status and development prospect forecast of global heat curing adhesive industry in 2022
- Oracle SQL table data loss
- Basic use of Metasploit penetration testing framework
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- Market status and development prospects of the global IOT active infrared sensor industry in 2022
- Market status and development prospect prediction of global fermented plant protein industry in 2022
- Market status and development prospect prediction of the global fire alarm sensor industry in 2022
- 论文阅读_中文医疗模型_ eHealth
- The reason why the entity class in the database is changed into hump naming
- Shuttle + alluxio accelerated memory shuffle take-off
猜你喜欢

The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article

Retirement plan fails, 64 year old programmer starts work again
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

移动端——uniapp开发记录(公共请求request封装)

Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
![[research materials] 2022q1 game preferred casual game distribution circular - Download attached](/img/13/5a67c5d08131745759fdc70a71cf0f.jpg)
[research materials] 2022q1 game preferred casual game distribution circular - Download attached

Valentine's day limited withdrawal guide: for one in 200 million of you

2022-02-11 daily clock in: problem fine brush

论文阅读_清华ERNIE

The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
随机推荐
Do you know UVs in modeling?
[research materials] annual report of China's pension market in 2021 - Download attached
【XSS绕过-防护策略】理解防护策略,更好的绕过
1118 birds in forest (25 points)
[USACO 2009 Dec S]Music Notes
The current market situation and development prospect of the global gluten tolerance test kit industry in 2022
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
document. The problem of missing parameters of referer is solved
RT thread flow notes I startup, schedule, thread
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Symbol of array element product of leetcode simple problem
Number of 1 in binary (simple difficulty)
[luatos sensor] 1 light sensing bh1750
Blog building tool recommendation (text book delivery)
第十九届浙江省 I. Barbecue
Shuttle + alluxio accelerated memory shuffle take-off
论文阅读_ICD编码_MSMN
Market status and development prospect prediction of global SoC Test Platform Industry in 2022
Network security textual research recommendation
@RequestMapping