当前位置:网站首页>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;
}
};

边栏推荐
- Problems encountered in fuzzy query of SQL statements
- String matching: find a substring in a string
- 《牛客刷verilog》Part II Verilog进阶挑战
- Thesis reading_ ICD code_ MSMN
- 1095 cars on campus (30 points)
- Huawei personally ended up developing 5g RF chips, breaking the monopoly of Japan and the United States
- 1110 complete binary tree (25 points)
- LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
- 最大连续子段和(动态规划,递归,递推)
- 112 stucked keyboard (20 points)
猜你喜欢

Interface frequency limit access

Thesis reading_ Tsinghua Ernie

Review the configuration of vscode to develop golang

Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)

Mobile terminal - uniapp development record (public request encapsulation)
![[research materials] 2021 China's game industry brand report - Download attached](/img/b7/a377b0b7c742078e2feb28ebfbca62.jpg)
[research materials] 2021 China's game industry brand report - Download attached

The reason why the entity class in the database is changed into hump naming

RT thread flow notes I startup, schedule, thread

逆袭大学生的职业规划

On typescript and grammar
随机推荐
Review the old and know the new: Notes on Data Science
MPM model and ab pressure test
1110 complete binary tree (25 points)
Symbol of array element product of leetcode simple problem
并发操作-内存交互操作
1099 build a binary search tree (30 points)
Analysis of proxy usage of ES6 new feature
Market status and development prospects of the global autonomous marine glider industry in 2022
I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
Retirement plan fails, 64 year old programmer starts work again
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
《牛客刷verilog》Part II Verilog进阶挑战
编译GCC遇到的“pthread.h” not found问题
document. The problem of missing parameters of referer is solved
Introduction to message queuing (MQ)
Preparation for school and professional cognition
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
1111 online map (30 points)