当前位置:网站首页>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;
}
};
边栏推荐
- Unity tool Luban learning notes 1
- [set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
- [XSS bypass - protection strategy] understand the protection strategy and better bypass
- MediaTek 2023 IC written examination approved in advance (topic)
- Number of 1 in binary (simple difficulty)
- Notes | numpy-10 Iterative array
- 【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
- 1094 the largest generation (25 points)
- MPM model and ab pressure test
- Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
猜你喜欢
JDBC database operation
Shuttle + alluxio accelerated memory shuffle take-off
String matching: find a substring in a string
Introduction to JVM principle
[XSS bypass - protection strategy] understand the protection strategy and better bypass
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Oracle SQL table data loss
Apache MPM model and ab stress test
随机推荐
Market status and development prospects of the global automatic tea picker industry in 2022
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
[set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
Notes | numpy-07 Slice and index
What is UUID
On typescript and grammar
Do you know UVs in modeling?
Thesis reading_ Tsinghua Ernie
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
Market status and development prospect prediction of global fermented plant protein industry in 2022
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python
【工具跑SQL盲注】
Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)
雇佣收银员(差分约束)
Caijing 365 stock internal reference: what's the mystery behind the good father-in-law paying back 50 million?
1115 counting nodes in a BST (30 points)
Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
Review the old and know the new: Notes on Data Science